rename plot names in a loop
Afficher commentaires plus anciens
How can I rename my figures in a loop after plotting my data?
I want the them to be called 'Data 1','Data 2','Data 3'.
Réponses (1)
Jan
le 25 Mar 2021
Store the handles of the figures in a vector:
FigList = gobjects(1, 3);
for k = 1:3
FigList(k) = figure;
end
% Then the naming is easy (but could be done in the loop above already?!)
for k = 1:3
FigList(k).Name = sprintf('Data %d', k);
end
1 commentaire
People often use the term "figure" to refer to either the figure window or to the axes contained in the figure window. Jan's code addresses the first usage. If you have multiple axes and you want to label each with a title, use the title function either right after you create the plot or at the end (using the axes handle.)
x = 0:360;
ax = gobjects(1, 2);
ax(1) = axes;
axis(ax(1), [0 360 -1 1])
plot(ax(1), x, sind(x))
figure
ax(2) = axes;
axis(ax(2), [0 360 -1 1])
plot(ax(2), x, cosd(x))
title(ax(1), "Sine")
title(ax(2), "Cosine")
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

