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.
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.
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.
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.
Related
I am using Matlab R2010a but could not find 'webread' function but with the message : "Undefined function or variable 'webread'." is shown.
The only available web function is 'web'.
How to download that function or solve the problem anyway?
As you can see at the bottom of the documentation for webread function, it has been introduced only in matlab 2014b.
You might find this (aka this), or this helpful as a substitute. I do not know whether any of them will work well on such an old version of Matlab though.
I tried using the .. command in MATLAB to generate Laguerre polynomials but I keep getting this error every time:
I found this in the help section:
Since I have defined x as symbolic I shouldn't be getting this error.
Also on website I found this which says that the function does not run in MATLAB.
Can anyone help? Thanks in advance
Like you say, and the matlab help says this function only works inside mupad, maybe in later versions it works in matlab console.
If you want to use it, write mupad in Matlab Command window and then use it in the mupad, matlab will return you the result as I show in the picture
In R2014b+, there is a laguerreL function available directly from within Matlab. However, a version of this function was introduced to MuPAD in R2009a. You can call the MuPAD version from within Matlab
syms x;
feval(symengine,'laguerreL',2,x)
or
evalin(symengine,'laguerreL(2,x)')
Both return x^2/2 - 2*x + 1.
You can read more about interacting with MuPAD functionality from Matlab here. However, I'd recommend browsing and searching the archived documentation for your specific version or using your built-in HTML documentation (e.g., doc mupad or doc 'calling mupad').
I want to use fig2texPS to export plots from MATLAB to LaTeX. I copied the the script to D:\Eigene Dokumente\MATLAB\fig2TexPS and added this folder as a path in MATLAB. Unfortunately, I receive the following error:
>> fig2texPS()
Undefined function 'find' for input arguments of type 'matlab.graphics.chart.primitive.Line'.
Error in fig2texPS (line 526)
lsh = double(find(handle(lshandles),'-class','graph2d.lineseries')); % find plots
PS: I use a version of the script which was updated in order to work with pdtlatex (http://pastebin.com/xK6KxxBT) that I found in the MATLAB Central File Exchange. The same error also occurs when I use the original script.
This might not be the answer you are looking for, but there is the marvelous matlab2tikz that does the job of conversion of figures quite nicely, which you could use as an alternative to fig2texPS.
I also use the function fig2texPS.m and it works very well. It might be an answer for your question to use an older version of Matlab. I am using 2013b and it works. While I have tried this function with Matlab 2015a, I was getting the same error message.
I hope my answer helps you with your problems.
Im trying to perform centerline extraction for cardiac CT images, and I am stuck. I need an example code that uses the "fast marching method". I got this code from mathworks.
I1=im2double(imread('se036.png'));
SpeedImage=I1*1000+0.001;
SourcePoint=[800;803];
DistanceMap= msfm(SpeedImage, SourcePoint);
figure
imshow(DistanceMap,[0 3400]) StartPoint=[9;14];
ShortestLine=shortestpath(DistanceMap,StartPoint,SourcePoint);
hold on
plot(ShortestLine(:,2),ShortestLine(:,1),'r')
But I get error message Undefined function 'msfm' for input arguments of type 'double'.
It appears you are trying to use the Matlab File Exchange submission Accurate Fast Marching but you haven't properly installed the code. The function file you downloaded, msfm.m, needs to be in a folder on your path or in the current working directory.
My teacher in the signal analysis course has given me some Matlab code that I have to execute in order to complete a home assignment. I have always been using GNU Octave without troubles, but this time there is this command that is giving me headaches.
[c8,g8]=fit(time, sin_4_harmonic,’fourier8’)
I cannot find the function "fit" in GNU Octave, which is referenced for Matlab at the following url http://www.mathworks.se/help/curvefit/fit.html
Does anyone knows which package should I load, or if there is any equivalent?
Thanks =)
As far as I know, that function is not present in any of the Octave packages. However, the best place to look for something similar would be the optim package, probably the function nonlin_curvefit. Looking at the documentation, the model fourier8 is of the type Y = a0+a1*cos(x*p)+b1*sin(x*p)... +a8*cos(8*x*p)+b8*sin(8*x*p).
A work-around may be using "polyfit" function. To get the values, use "polyval".