MATLAB: Plotting several graphs in one plot

plotplottingsignal processing

So I've been on this problem for quite some time now, and I've looked everywhere online but I cant find it anywhere. So hopefully somebody could help me with this.
So basically, I am trying to plot particle filters through 50 time steps. I get a graph for that plot. Although, my deliemma is when I try to loop the result so that I get the graph 20 times, on the same plot.
I want to have a single plot with 20 different graphs of the same function. I dont know if thats really clear. but heres my code in very short term.
for test = 1:20
hold on
for k = 1 : 50
% True Values of State & Measurement
x = 0.5 * x + 25 * x / (1 + x^2) + 8 * cos(1.2*(k-1)) + sqrt(Q) * randn;
y = x^2 / 20 + sqrt(R) * randn;
% Particle filter
for i = 1 : 200
Xminus(i) = 0.5 * X(i) + 25 * X(i) / (1 + X(i)^2) + 8 * cos(1.2*(k-1)) + sqrt(Q) * randn;
Y = Xminus(i)^2 / 20;
Likelihood = y - Y;
q(i) = (1 / sqrt(R) / sqrt(2*pi)) * exp(-Likelihood^2 / 2 / R);
end
.
.
.
end %for the k=1:50
t = 0 : 50;
figure;
subplot (3,1,1)
plot(t, x0, 'b.', t, xPFArr, 'k-');
xlabel('Time Step');
ylabel('State');
subplot (3,1,2)
plot(t, x0, 'b.', t, xAuxArr, 'g:');
xlabel('Time Step');
ylabel('State');
subplot (3,1,3)
plot(t, x0, 'b.', t, xRegArr, 'r:');
xlabel('Time Step');
ylabel('State');
end %for the test
So each of the subplots are diffrent particle filters. I tried doing hold on before the k loop but for some reason it displays the first loop so time step to 50 of one graph. And then when it goes for the 2nd iteration my data has 100 steps instead of 50.
DOes anybody know why? And how I could fix this problem? That would be great,
fabio

Best Answer

oh so I found out where I made a mistake
In the test loop 1:20 I had to redefine my variables in the plotting part. Meaning xPFArr[], xAuxArr[], xRegArr[] so that I get 50 time steps each loop.
Thanks for the quick reply though
Related Question