Effacer les filtres
Effacer les filtres

Create new Figures with MATLAB live script

37 vues (au cours des 30 derniers jours)
Ahmad
Ahmad le 23 Fév 2024
Commenté : Ahmad le 26 Fév 2024
After using MATLAB live script, I noticed that when I create figures, the numbering does not increment by 1 as expected. Instead, it skips figures 2 to 4. For example, if I write the code in live script:
figure
figure
figure
the output will be figures 1, 5, and 6. How can I resolve this problem?

Réponse acceptée

Austin M. Weber
Austin M. Weber le 24 Fév 2024
Modifié(e) : Austin M. Weber le 24 Fév 2024
Hi @Ahmad,
I recommend putting the following command:
close all
at the beginning of your MATLAB live script. This should reset the figure numbers before the rest of the script is run. Alternatively, you can manually assign numbers to your figures however you like:
figure(1)
figure(2)
figure(57)
  3 commentaires
Austin M. Weber
Austin M. Weber le 25 Fév 2024
I have come across the same issue in the past where I would execute a block of code in an .mlx file and then the plots would get combined. The solution that I have found for this is to separate the figures into separate blocks using a section break (%%):
hfig = figure;
Num=hfig.Number;
for var3=1:numel(d)
fig1=figure(Num);
hold on
plot(VTh,reshape(WsMax(:,1,var3),1,[]))
title('plot 1');
xlabel('VTh');
ylabel('Ws');
hold off
end
%% Start new section here
for var3 = 1:numel(d)
fig2=figure(Num+1);
hold on
plot(VDC,reshape(WsMax(1,:,var3),1,[]))
title('plot 2');
xlabel('VDC');
ylabel('Ws');
hold off
end
Note that in .mlx files you might run into problems trying to execute a for-loop across multiple sections, so I split your code into two for-loops. You can adjust this however you need. Hopefully you can get your script to work now.
Alternatively, you can try running your code in a normal script file (.m) instead of a live script file.
Ahmad
Ahmad le 26 Fév 2024
Initially, the .mlx file was working fine, but later on, it only displayed one figure while the other was missing. however, everything runs smoothly in the .m file.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Objects dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by