1

I have Matlab code such as:

f=figure(1)
plot(x,y)
hold on
plot(x1,y1)
hold on
...
plot(xf, yf)
%want to save this into a VARIABLE, NOT into a .fig, .png, jpg, or other kind of file

So if it is possible to save this into some variable var_fig, I would like to later open the figure (such as in a subplot with multiple saved figures/plots) doing something like

showfig(var_fig)

Is this possible in Matlab?

aaa
  • 39
  • 1
  • 8
  • 1
    Possible duplicate of [Turn a MATLAB plot into image](https://stackoverflow.com/questions/1915891/turn-a-matlab-plot-into-image) – beaker Feb 01 '18 at 21:48
  • Another way of solving the problem of 'preserving figure data' in general is to store the raw-data in a file and load it at the beginning of your 'plot figure' script. In this case, you would only store `x,y,x1,y1,xf,yf` in a *.mat file using the save command above, then load your data before executing your figure script. – user2305193 Feb 02 '18 at 13:05

1 Answers1

3

It's possible but not recommended. You can save any variable using save:

myfigure = gcf; %store current figure in a variable
save('filename','myfigure');

However according to Matlab be warned:

Warning: Figure is saved in filename.mat. Saving graphics handle variables
can cause the creation of very large files. To save graphics figures,
use savefig. 

Here's how to use savefig

user2305193
  • 2,079
  • 18
  • 39