How can I add title to plots before the loop
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
The problem with my code is it creates the titles, xlabel and ylabel 500 times each, so this makes the code slow to execute. Is there any way to put these outside the for loop (j=1:50) making titles, xlabel and ylabel to create only 10 times?
figure
for i=1:10
for j=1:50
subplot(2,1,1)
plot()
title(sprintf('%d',i))
drawnow
subplot(2,1,2)
plot()
xlabel('something')
ylabel('something else')
title(sprintf('%d',i))
drawnow
end
end
3 Kommentare
dpb
am 16 Jul. 2020
Well, when you include
%subplot(2,1,1) -> title(sprintf('%d',i))
you've just made it nonstatic so if you want it to change, you'll have to rewrite it....not much way around it.
If the x,y labels are static, then as said, look at the animation documentation for how to just change the data in the plot instead of redoing it from scratch. That will be faster.
Antworten (1)
Voss
am 20 Dez. 2023
figure
for i=1:10
ax1 = subplot(2,1,1)
title(ax1,sprintf('%d',i))
ax2 = subplot(2,1,2);
xlabel(ax2,'something')
ylabel(ax2,'something else')
title(ax2,sprintf('%d',i))
for j=1:50
%calculations
plot(ax1,results_for_ax1)
plot(ax2,results_for_ax2)
drawnow
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!