# Bubbels not connecting in plot command

1 view (last 30 days)
upinderjeet on 8 Oct 2014
Edited: Adam on 9 Oct 2014
Hello
I am using the following code and want the figure(2) to have bubbles connected with the 2 dashed lines(as you can see from the code). But for some reason I dont know, I am just getting the bubbles and no interconnection between the bubbels. This bothers me bcoz my trajectories are not visible clearly. Please help out. Please run the following code and see figure(2) plot if you cant understand what I mean.The code is:
clear all
clc
Ek=50;alpha=0.75;
for k=0:20,
figure(1)
stem(k,Ek);hold on
figure(2)
plot(k,3*(Ek)^0.5,'k--',k,-3*(Ek)^0.5,'k--o');hold on
Ek=(alpha^2)*Ek+1;
end
for j=1:100,
Xk=((50)^0.5)*randn(1,1);
for i=0:20,
figure(2)
plot(i,Xk,'b--o');hold on
Xk=alpha*Xk+randn(1,1);
end
end

Edited: Adam on 8 Oct 2014
Something more like this to replace your bottom section (i.e. starting from your for j = 1:100 loop) should give you joined up plots. The result looks incomprehensible to me, but I think it is achieving what you want.
i = 0:20;
for j = 1:100
Xk = ((50)^0.5)*randn(21,1); Xk(2:end) = alpha*Xk(2:end)+randn(20,1);
figure(2)
plot(i,Xk,'b--o');hold on
end
There may be ways to further tidy up that code, but I was mostly focussed on just vectorising the Xk values to plot in one instruction rather than work out exactly what is happening to Xk!
##### 3 CommentsShow 1 older commentHide 1 older comment
Edited: Adam on 9 Oct 2014
You can use:
plot(i,Xk,'--o','Color', [r g b]);hold on
to plot in the colour defined by [r g b]
So if you wanted 100 colours you could create them (though I agree they would not be distinguishable. Alternatively you can just define a cell array of 6 (or however many) RGB colours and in your plot command just plot as
plot(i,Xk,'--o','Color', colours{ mod( j, 6 ) + 1 ) };hold on
You can also use the other method of describing colours as e.g.
colours = {'r', 'g', 'b', 'k', 'y', 'm'};
which works with the above code too, but that is more limited as I think there are only ~8 colours defined that way and yellow is rather useless.
I think even that way though you have too much information on the plot to understand what is happening and from my attempts at joining the dots above it is quite possible that your trend could move about enough that one line of a given colour will cross over another, meaning that just 6 colours without trend lines will not give you that information.
upinderjeet on 8 Oct 2014