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 个)
Jan
2021-3-25
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

