How to subplot using for loop?

9 ビュー (過去 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 Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by