Subplots made by multiple plots

조회 수: 2 (최근 30일)
Laurens
Laurens 2011년 12월 28일
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!

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 12월 28일
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))

추가 답변 (1개)

Demetrio Rodriguez Tereshkin
Demetrio Rodriguez Tereshkin 2016년 2월 23일
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

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by