creating several subplots with for loop

1 view (last 30 days)
I'm trying to take data that is 86 rows long and generate a series of subplots. The code would generate 5 subplots per figure and repeat such that the first would be rows 1-5, second rows 6-10, etc. Ex.
Fig1
a = row 1
b = row 2
c ...
e = row 5
I have been able to generate this plot manually for 5 rows at a time; i want to loop this script to generate sets of 5 subplots per figure until all rows have been plotted.
The code I used to generate the 5 rows successfully is as follows:
start = 1
finish = 5
rows = finish - start
figure
for i = start:1:finish
hold on
subplot(rows+1,1,i);
plot(chan1(i,2:end));
end
Any suggestions on how to expand this to run all the data at once would be greatly appreciated!

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 26 Feb 2016
t=1:100;
y=rand(80,100);
for k=1:5:size(y,1);
s=y(k:k+4,:);
figure;
for ii=1:5
subplot(5,1,ii);
plot(t,s(ii,:))
end
end

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!