Reputation: 914
I am using Matlab's Mapping Toolbox to create and print a conically projected figure of North America. When I run the code inside the IDE the plots are printed and saved correctly, but when running the same script on the command line using -nodisplay -nodesktop -nosplash I run into a very strange problem.
During the print() function call, Matlab stops running the script without any error, warning, or crash log. Matlab does not actually crash...it just stops executing my code. Printing a figure without a display is suppose to be possible according to this.
Other people have come across a similar issue and have asked about it on the MathWorks website.
Here is some code to reproduce this problem.
So far, no one has come up with a solution. Does anyone have any suggestions? Thanks in advance!
Edit 1:
Here is some self contained code to reproduce the problem. I have tested on both R2011b and R2012a.
figure(1)
axesm eckert4; framem; gridm; axis off; tightmap
load geoid
contourfm(geoid, geoidrefvec, -120:20:100, 'LineStyle', 'none');
coast = load('coast');
geoshow(coast.lat, coast.long, 'Color', 'black')
contourcbar
print('-f1','-dpng','-r200','-painters', 'example');
Upvotes: 3
Views: 4751
Reputation: 335
The following warnings appear if you run MATLAB from scripts using, e.g.,
#!/bin/sh
nohup matlab -nodisplay -nodesktop -r myCode > myLog.log &
exit
.
[Warning: Objects of graph2d.lineseries class exist - not clearing this class or
any of its superclasses]
[Warning: Objects of scribe.legend class exist - not clearing this class or any
of its superclasses]
[Warning: Objects of graphics.panbehavior class exist - not clearing this class
or any of its superclasses]
[Warning: Objects of graphics.zoombehavior class exist - not clearing this class
or any of its superclasses]
[Warning: Objects of graphics.rotate3dbehavior class exist - not clearing this
class or any of its superclasses]
[Warning: Objects of graphics.datacursorbehavior class exist - not clearing this
class or any of its superclasses]
[Warning: Objects of graphics.ploteditbehavior class exist - not clearing this
class or any of its superclasses]
The problem is that the matlab code would like to display a figure, plot or something else, but the option -nodisplay
prohibits it. I solved this problem by simply add the following lines to my code set(gcf, 'visible','off');
and at the end close gcf; clear gcf;
. Now the plot legend was as in the first plot without shift and I got no warning.
Upvotes: 2
Reputation: 1273
I've come to the conclusion that this problem is not solvable, and is a bug.
The closest I've gotten to solving the problem is using the following code from the shell:
$ matlab -nosplash -nodisplay < makefigure.m
makefigure.m:
plot(randn(100,1));
set(gca,'Units','normalized','Position',[0.13 0.11 0.775 0.815]);
set(gcf,'Units','pixels','Position',[4 4 1200 900]); %# Modify figure size
hgexport(gcf,'myfig.png',...
hgexport('factorystyle'),'Format','png');
Which will output a png file 'myfig.png' of 1200x900 pixels. Unfortunately, while the image is the size I want, the graph itself is still the small size. I'm not certain of the cause of this, but I believe it has something to do with the fact that Matlab is object oriented and that the axes are supposed to be linked to the figure size (that's what the 'Position' variable for gca is normalized to). For whatever reason, this doesn't happen specifically when the display is turned off. I doubt this will be addressed anytime soon by Mathwoks, and I can't blame them since the vast majority of Matlab users use the GUI.
The one potential clue that could help anyone with the means to fix this is that it gives an error when running on the command line:
Warning: Objects of graph2d.lineseries class exist - not clearing this class
or any of its super-classes
I searched for a solution but just found more questions. My suspicion is that if someone can figure out what that means, you can fix this issue. For now, I will once again go back to python because with Matlab I just spend hours dealing with inconveniences instead of being productive.
Edit: In case it helps, this is Matlab 2012a on Linux ... 2.6.35.6-45.fc14.x86_64 #1 SMP ... x86_64 x86_64 x86_64 GNU/Linux
Upvotes: 1