MATLAB:选择标题,xlabel,ylabel for For循环中的Plots

问题描述 投票:0回答:1

在Matlab中,我输出了一系列由for loop绘制的图。迭代通过要绘制的for循环的数据在多维矩阵中构造。但是我需要在for循环中使用titlexlabelylabel来通过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。海拔高度

matlab for-loop plot
1个回答
1
投票

正如评论中所建议的那样,为您的标签使用单元格数组并为其编制索引:

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 
© www.soinside.com 2019 - 2024. All rights reserved.