Saving figure in app designer.

15 次查看(过去 30 天)
Hi, I want to save a figure in app designer called app.ScanDataPlot.
The code below saves the figure (but just the data, with x and y axes but with no titles). I also want to include the legend of the graph (for the different curves) and include the x and y axes titles. How can I do this?
The code does not save the figure as .png, just as .fig. Any ideas how to get the figure in .png format also?
% Create a temporary figure with axes.
figScan = figure;
figAxes = axes(figScan);
% Copy all UIAxes children, take over axes limits and aspect ratio.
allChildren = app.ScanDataPlot.XAxis.Parent.Children;
copyobj(allChildren, figAxes)
figAxes.XLim = app.ScanDataPlot.XLim;
figAxes.YLim = app.ScanDataPlot.YLim;
figAxes.ZLim = app.ScanDataPlot.ZLim;
figAxes.DataAspectRatio = app.ScanDataPlot.DataAspectRatio;
% Save as png and fig files.
fileName = fullfile([pathway,'\data','\fig-file\'], 'WorstLocation.fig');
saveas(figScan, fileName, 'png');
savefig(figScan, fileName);

采纳的回答

Joost
Joost 2020-5-5
You might want to take a look at this contribution:
Regarding the saving as png: I guess that it does not work because fileName already has the fig extension.
Could you give this a try:
fileName = fullfile([pathway,'\data','\fig-file\'], 'WorstLocation');
saveas(figScan, [fileName '.png'], 'png');
savefig(figScan, [fileName '.fig']);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by