Create new Figures with MATLAB live script

71 次查看(过去 30 天)
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?

采纳的回答

Austin M. Weber
Austin M. Weber 2024-2-24
编辑:Austin M. Weber 2024-2-24
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 个评论
Austin M. Weber
Austin M. Weber 2024-2-25
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 2024-2-26
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by