在Matlab中,我输出了一系列由for loop
绘制的图。迭代通过要绘制的for循环的数据在多维矩阵中构造。但是我需要在for循环中使用title
,xlabel
和ylabel
来通过for循环为每次迭代更改其选定的字符串。
这是代码:
lat = [40 42 43 45 56]'
lon = [120 125 130 120 126]'
alt = [50 55 60 65 70]'
time = [1 2 3 4 5]'
position = cat(3, lat, lon, alt);
for k = 1:3
figure
plot(time, position(:,k),'LineWidth', 2, 'Color', 'b')
xlabel('Latitude Time');
ylabel('Latitude Mag');
title('Time v. Latitude');
end
如何获取在for循环中输出标签的图:
第一次迭代:
xlabel
=纬度时间ylabel
= Latitude Mag title
=时间v。纬度
第二次迭代:
xlabel
=经度时间ylabel
=经度Mag title
=时间v。经度
第三次迭代:
xlabel
=海拔高度时间ylabel
=海拔高度mag title
=时间v。海拔高度
正如评论中所建议的那样,为您的标签使用单元格数组并为其编制索引:
my_xlabels = {'Latitude Time';'Longitude Time';'Altitude Time'};
my_ylabels = {'Latitude Mag';'Longitude Mag';'Altitude Mag'};
my_titles = {'Time v. Latitude';'Time v. Longitude';'Time v. Altitude'};
for k = 1:3
figure
plot(time, position(:,k),'LineWidth', 2, 'Color', 'b')
xlabel(my_xlabels{k});
ylabel(my_ylabels{k});
title(my_titles{k});
end