rename plot names in a loop

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
Jan le 25 Mar 2021

1 vote

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")

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Version

R2020b

Question posée :

le 25 Mar 2021

Commenté :

le 25 Mar 2021

Community Treasure Hunt

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

Start Hunting!

Translated by