Multiple figures in for loop
Mostra commenti meno recenti
Hello,
I would like to run a for loop that produces multiple plots. I looked at other questions that ask this, but they don't seem to fit the data set I have.
This is code I have, if written out (without for loop):
N = length(y1(:,1));
T = (0:N-1)/fs;
figure
subplot(2,3,1)
plot(T,y1(:,1))
subplot(2,3,2)
plot(T,y2(:,1))
subplot(2,3,3)
plot(T,y3(:,1))
subplot(2,3,4)
plot(T,y4(:,1))
subplot(2,3,5)
plot(T,y5(:,1))
subplot(2,3,6)
plot(T,y6(:,1))
This is the code I have so far with the for loop:
figure
for q = 1:length(txtfiles); % This is the number of files I have for my data (in numerical matrices), I have 24 files that I'm interested in, where I'd like to look at 6 files at a time and only the first column
cnt = 1;
for bor=1:6:24
plot(T,y1(:,1))
cnt=cnt+1;
end
end
But I get stuck because I can't do this:
figure
for q = 1:length(txtfiles);
cnt = 1;
for bor=1:6:24
plot(T,y(q)(:,1))
plot(T,y(q+1)(:,1))
plot(T,y(q+2)(:,1))
plot(T,y(q+3)(:,1))
plot(T,y(q+4)(:,1))
plot(T,y(q+5)(:,1))
cnt=cnt+1;
end
end
Thank you for the help in advance!
3 Commenti
Aquatris
il 17 Lug 2018
It is not clear what you are trying to achieve. You used subplot in the first codes but not in the ones with for loop. What is the relation between y and y1,y2,y3,y4,y5,and y6? DO you want all the plots in a single plot or 6 subplot?
Geoff Hayes
il 17 Lug 2018
Krithika - in your original code, you seem to have six variables for each of the subplots. If instead of using individual variables but have a cell array or matrix (if the dimensions for each y* are the same) then you can easily iterate over your single array like
for k=1:6
subplot(2,3,k);
plot(T,allData(:,1,k));
end
where allData is your three-dimensional matrix that has all data from all variables (assuming that dimensions for all y* are the same).
Krithika A
il 18 Lug 2018
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!