How to label x-axis for multiple subplots with different names?
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Penny Chen
il 16 Lug 2017
Commentato: Star Strider
il 13 Giu 2021
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 Commenti
Risposta accettata
Star Strider
il 16 Lug 2017
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 Commenti
Più risposte (1)
Walter Roberson
il 16 Lug 2017
Modificato: Walter Roberson
il 16 Lug 2017
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
Vedere anche
Categorie
Scopri di più su Axis Labels in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!