Reputation: 117
I am new to Matlab and trying to save my current figure to file. So, I have followed the official documentation at http://www.mathworks.co.uk/help/matlab/ref/savefig.html#inputarg_h and entered the following into Matlab:
figure;
surf(peaks);
savefig('PeaksFile.fig');
close(gcf);
However, I get the following error:
Undefined function 'savefig' for input arguments of type 'char'.
If I type in:
help savefig
I get the following error:
savefig not found.
Any ideas on what's going on? I would have thought that savefig comes with all releases of Matlab rather than requiring any add-ons. The version of my Matlab is 2013a.
Upvotes: 3
Views: 3712
Reputation: 1316
The two answers are great. Another option which I believe has been around for many, many years is to use the print command:
print -f1 -djpeg bob.jpg
The -f1
is the figure number and obviously bob.jpg
is the filename to which you want to write. I have code going back to 2007 using that but I am sure it goes back earlier than that. So it should work with pretty much any version you are using.
For that matter, using print, you can write PS, EPS, TIFF, PNG as well as JPG.
Upvotes: 0
Reputation: 14939
You're using R2013a, while savefig
was released in R2013b. I can't test if the functionality is identical as I don't have R2013b (or newer) on this computer, but you might try the savefig
-function on the File Exchange, or other alternatives available in the R2013a-release.
Upvotes: 2
Reputation: 796
It looks as though savefig is not implemented in Matlab version earlier than 2013b (from some experimentation and a comment at the end of http://www.mathworks.com/matlabcentral/fileexchange/10889-savefig). Instead, use saveas(h,'filename.ext'), which is documented here http://www.mathworks.co.uk/help/matlab/ref/saveas.html and is certainly included in 2012a.
Upvotes: 3