How to subplot using for loop?

조회 수: 5 (최근 30일)
AS
AS 2021년 11월 29일
답변: dpb 2021년 11월 29일
I want to subplot in for loop.
I have 3d matrix (M) with dimension (3000*8*10). I want to subplot for 8 variables for 10 runs in for loop.
for k=1:10
cc(:,:,k)=M(:,:,k)
subplot(2,4,1)
plot(cc(:,1),cc(:,1));
subplot(2,4,2);
plot(cc(:,1),cc(:,2));
subplot(2,4,3);
plot(cc(:,1),cc(:,3));
subplot(2,4,4);
plot(cc(:,1),cc(:,4));
subplot(2,4,5)
plot(cc(:,1),cc(:,5));
subplot(2,4,6)
plot(cc(:,1),cc(:,6));
subplot(2,4,7)
plot(cc(:,1),cc(:,7));
subplot(2,4,8)
plot(cc(:,1),cc(:,8));
end
But, i got similar plot in k=10.
How do I do this? Thanks!

답변 (1개)

dpb
dpb 2021년 11월 29일
for m=1:10
figure
for n=1:8
subplot(2,4,n)
plot(MM(:,n,m));
end
end
The above plots each against the ordinal position in the column for columns 1:8 of each plane.
If there's an X variable that you've not identified against which to plot, add it in the X argument position in the call to plot() and adjust the indices to the Y argument as needed.

카테고리

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