How to label x-axis for multiple subplots with different names?
19 次查看(过去 30 天)
显示 更早的评论
I have plotted multiple plots in a single figure in matlab. Now I want to label axes (X, Y) labels with different name (ex: A1, A2). How can I do that?
I have tried with the following codes, however the problem is that I don't know how to assign different names in the for loop.
for i = 1:1:2
subplot(1,2,i)
plot(t,X(:,i))
xlabel('time');
ylabel('here I want to put different names, for the first subplot, I want it to be A1, for the second subplot, I want it to be A2,');
hold on
end
0 个评论
采纳的回答
Star Strider
2017-7-16
Create a cell array with the different y-axis labels, then index into it:
y_label_names = {'Subplot 1', 'Subplot 2', 'Subplot 3', 'Subplot 4', 'Subplot 5', 'Subplot 6', 'Subplot 7', 'Subplot 8', 'Subplot 9'};
t = 1:20; % Create Data
X = rand(20,9); % Create Data
for i = 1:1:9
subplot(2,5,i)
plot(t,X(:,i))
xlabel('time');
ylabel(y_label_names{i});
hold on
end
Change the nine strings in ‘y_axis_names’ to the ones you want.
4 个评论
更多回答(1 个)
Walter Roberson
2017-7-16
编辑:Walter Roberson
2017-7-16
names = {'John', 'Paul', 'George', 'Ringo', 'Marie', 'Lise', 'Ada', 'Hypatia', 'Heddy'};
for i = 1:1:9
subplot(2,5,i)
plot(t,X(:,i))
xlabel('time');
ylabel( sprintf('%s is #%d', names{i}, 10-i) );
hold on
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!