Re: can matlab plot data by condition



On 10 31 , 9 30 , "Diederick Niehorster" <n...@xxxxxxxx> wrote:
"Ha Wanger" <virtualcyberinfo+nos...@xxxxxxxxx> wrote in
message <fg98ea$iv...@xxxxxxxxxxxxxxxxxx>...





I have two matrix like these:
X = [1 2 3 4 5 6]
Y = [-3 -1 -2 2 -1 1]

I want to have a line-dot plot and when Y<0, the dot is
red;
when Y>0, the dot is blue.

Now I'm using the follwing method:
1. creat two matrixs foo1 & foo2 from [X;Y]
foo1 = [1 2 3 5 ; -3 -1 -2 -1]
foo2 = [4 6 ; 2 1]
2. plot(foo1(1,:),foo1(2:,),'.r')
plot(foo2(1,:),foo2(2:,),'.b')
plot(X,Y,'-')

actually,the matrixs X & Y are very big so this method is
some inefficient.

Can anyone give me a better method? Thanks!

I think the easiest way is to plot the line and the dots
seperately:
X = [1 2 3 4 5 6];
Y = [-3 -1 -2 2 -1 1];
plot(X,Y,'k-');
hold on;
plot(X(Y<0),Y(Y<0),'ro');
plot(X(Y>=0),Y(Y>=0),'bo');

enjoy ;)- -

- -

Good! it works

.