I'm trying to plot several subplots in a single figure.
The total number of subplots is dependent on the maximal value in a matrix: maximal value of 'i'.
I'd like to plot two variables in two subplots below each other for every value of i :slagtijd_start & slagfrequentie_start
So when the maximum value of i = 3, we have a subplot matrix of 2x3 axes, if i = 4 --> 2x4 axes etc.
Plotting on the right postions works, except that matlab erases the previous subplots (previous values of i). In this case i = 3 and the figure only displays the two latest subplots. I've tried different things with 'hold on' etc. But I can't figure it out. It's probably a simple trick.
I've posted my code and resulting figure below,
Thanks in advance,
Mochje
figure(6)
hold on
for i = 1:max(piektijden_start(:,2))
startnummer = find(piektijden_start(:,2) == i);
slagtijd_start= diff(piektijden_start(startnummer));
slagfrequentie_start= (60./slagtijd_start);
subplot(2,i,i),plot(piektijden_start(startnummer(1:end-1),1),slagtijd_start)
hold on
xlabel('Tijd [s]')
ylabel('Slagtijd [s]')
title('Slagtijd')
subplot(2,i,i+i),plot(piektijden_start(startnummer(1:end-1),1),slagfrequentie_start)
hold on
plot(piektijden_start(startnummer(1:end-1),1),slagfrequentie_start,'.r')
xlabel('Tijd [s]')
ylabel('Slagfrequentie [N/min]')
title('Slagfrequentie')
end