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

采纳的回答

Star Strider
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
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 CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by