Subplots made by multiple plots
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Laurens
am 28 Dez. 2011
Beantwortet: Demetrio Rodriguez Tereshkin
am 23 Feb. 2016
Hi,
I would like to draw a figure consisting of 3 subplots, each made by 4 plots.
Here's my code, to make it more clear...
hold all;
for i=1:4
subplot(1,3,1);
plot(S1(:,1,i), S1(:,2,i), c(i));
xlim([0 1]);
subplot(1,3,2);
plot(S2(:,1,i), S2(:,2,i), c(i));
xlim([0 1]);
subplot(1,3,3);
plot(S3(:,1,i), S3(:,2,i), c(i));
xlim([0 1]);
end
hold off;
My problem is that only the last plots are drawn in the subplots. So I see only one line per subplot, instead of the 4 I intended. Can anyone help me fix this?
Thanks!
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 28 Dez. 2011
Each subplot needs to be held individually.
figure; hold on
subplot(121)
hold on
plot(1:3)
plot(rand(1,3))
subplot(122)
hold on
plot(4:6)
plot(rand(1,3))
0 Kommentare
Weitere Antworten (1)
Demetrio Rodriguez Tereshkin
am 23 Feb. 2016
Or just use hold on after subplot.
% some values
x(1,:) = 1:10;
x(2,:) = x(1,:)-1;
y = x.^2;
% subplots in a loop replace each other
fig1 = figure('Name', 'subplots_replacement');
for i = 1:2
subplot(1, 2, 1)
plot(x(i,:))
subplot(1, 2, 2)
plot(y(i,:))
end
% subplots in a loop overlap
fig2 = figure('Name', 'subplots_add');
for i = 1:2
subplot(1, 2, 1)
hold on % this helps
plot(x(i,:))
subplot(1, 2, 2)
hold on % this helps
plot(y(i,:))
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!