在 Matlab 中,我通过for loop
. 要绘制的遍历 for 循环的数据在多维矩阵中构造。不过,我需要的title
,xlabel
以及ylabel
在for循环通过改变其选定的字符串每次迭代的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
= 纬度 Mag title
= 时间 v. 纬度
第二次迭代:
xlabel
= 经度时间ylabel
= 经度 Mag title
= 时间 v。经度
第三次迭代:
xlabel
= 海拔时间ylabel
= Altitude 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句