What is wrong with this savefig and Openfig in the following script in the FOR Loop?

2 次查看(过去 30 天)
Openfig does not open the saved fig files correctly. seems like the .fig file is corrupted. The .fig file can be opened if i removed the For Loop and run it one at a time.
Code example as follows: %% g=[1 2 3];
for g = 1:length(g)
f1=figure;
y= 1:1:100; x= 1:1:100;
subplot (211);
plot(x,y, 'DisplayName','ADS value'); hold on;
scatter(x,y, 'x','DisplayName','ADS value'); hold off;
ttitle = sprintf('%d plot 1',g); title(ttitle);
subplot (212)
y1= 1:1:200; x1= 1:1:200;
plot(x1,y1, 'DisplayName','ADS value'); hold on;
scatter(x1,y1, 'x','DisplayName','ADS value'); hold off;
ttitle = sprintf('%d plot 2',g); title(ttitle);
legend('Location','southeastoutside');
filename = sprintf("testing (%d).fig", g); savefig(f1,filename);
end
openfig("testing (1).fig")
openfig("testing (2).fig")
openfig("testing (3).fig")
% Appreciate if you can tell me what's wrong with the code. % Thank you.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by