Multiple figures in for loop
古いコメントを表示
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 件のコメント
Aquatris
2018 年 7 月 17 日
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
2018 年 7 月 17 日
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
2018 年 7 月 18 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!