MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by JoE on 9 Jan 2013

Hi.

My question is as simple as it looks like. I've tried many ways to do it, but it is still not doing, what I want. I have a gui, which contains axes, where my plot is displayed. And I need to save this plot to file (of whatever extension).

In forums there are a lot of solutions and some of them particulary worked. That means the figure wasn't complete (just a part of it has been saved in file) or in file has been saved something like printscreen of my gui.

Is there a simple solution for that? Thank you very much for any answers.

*No products are associated with this question.*

Answer by Image Analyst on 9 Jan 2013

The most popular solution for saving figures is mentioned in The FAQ

## 5 Comments

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58335#comment_121639

Please post what you have tried so far. The answer depends on the format you want to save the file in, e.g. EMF, PDF, FIG or PNG, so please specify this.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58335#comment_121793

Especialy I need jpg and eps in color and greyscale as well. I have tried "hgsave", "saveas", "print" and more commands, but probably I'm doing something wrong, when it's not working correctly.

I can attached a printscreen of my gui, but I have no idea how. Thanks for help.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58335#comment_121804

I have just solved this problem. I just put command "figure()", and now the plot appears in separately window with save button and all tools I may need in future.

Thank you for your time.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58335#comment_121808

Then please post the code you have tried and explain the occurring problems with details, e.g. if the result differs from your expectations or you get an error message.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58335#comment_130704

function SaveAs_Callback(~, ~, ~)

global PlotData x y X n

figure();PlotData = plot (x,y,'.','MarkerEdgeColor','k','MarkerSize',8);

hold on

set (gca,'XTick',0:0.1:1)

set (gca,'XTickLabel',{'0','0.1','0.2','0.3','0.4','0.5','0.6','0.7','0.8','0.9','1.0'})

xlabel ('phase')

ylabel ('intensity')

a = (0:0.001:1);

b = X(1,1);

for i = 1:n

end

PlotFit = plot (a,b);

hold off

set (PlotFit,'Color','k','LineWidth',2)

This is part of my code. It plots graph of two measured variables (x,y) and theoretical fit over this graph.

My goal was to save this picture using Save context menu. Idea was to open "Save as" dialog box. But unsuccessfull. So I tried this and put the keyword

figure(). After clicking on this button picture is opened in new window with all of these edit functions, save buttons etc. Not what I want, but one step closer to that. :)Thanks for any advices.