gcf repeatedly returns gui and not newly created figures
Show older comments
Hi all,
I am using a GUIDE-created gui to run a Simulink model and part of the output is a series of figures. I am creating the figures in a loop and printing each one to file within the same loop, as follows:
foldname = char("pitch_bounce_plots " + datestr(now,'yyyy_mm_dd_HH_MM_SS'));
mkdir(foldname);
for k = 1:18
figure;
surface(X,Y,charvalues(:,:,k));
view(3);
xlabel(xstring);
ylabel(ystring);
zlabel(charlabels(k));
grid on;
flname = foldname + "\figure_" + string(get(gcf,'Number'));
print(flname,'-dpng');
end
Each of the 18 plots is presented to me on screen one at a time, each overlaying the last. And yet, in the folder I have 18 images of the gui! Presumably, gcf is not referring to what I consider to be the current figure. What is also slightly weird is that the first image has all grey buttons and the other 17 have the gui run button highlighted in blue.
How do I ensure that my print command prints the figure that is on top at the time?
Eventually, I may make all the plot figures invisible and only print them to file, but for now I would like to see them.
Regards,
Simon.
Accepted Answer
More Answers (1)
Simon Aldworth
on 15 Nov 2018
0 votes
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!