Borrar filtros
Borrar filtros

Create new Figures with MATLAB live script

37 visualizaciones (últimos 30 días)
Ahmad
Ahmad el 23 de Feb. de 2024
Comentada: Ahmad el 26 de Feb. de 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?

Respuesta aceptada

Austin M. Weber
Austin M. Weber el 24 de Feb. de 2024
Editada: Austin M. Weber el 24 de Feb. de 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 comentarios
Austin M. Weber
Austin M. Weber el 25 de Feb. de 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 el 26 de Feb. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by