How to subplot using for loop?

11 vues (au cours des 30 derniers jours)
AS
AS le 29 Nov 2021
Réponse apportée : dpb le 29 Nov 2021
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!

Réponses (1)

dpb
dpb le 29 Nov 2021
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.

Community Treasure Hunt

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

Start Hunting!

Translated by