Create new Figures with MATLAB live script
조회 수: 67 (최근 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?
댓글 수: 0
채택된 답변
Austin M. Weber
2024년 2월 24일
편집: Austin M. Weber
2024년 2월 24일
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
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!