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'.

回答(1 个)

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 个评论

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

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品

版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by