From: RUSSELL on
In the following code what i want to achieve is the following using the scatter function (for now i am just testing with random data):

1. plot the x,y positions which have varying marker sizes depending
on the absolute value of 'velx'

I have gotten this to work by setting S=(abs(velx)/10.);

2. velx has a range in values from -300 to 300. So
additionally i would like, for negative
values i would like the scaled points to be e.g. red
For postive values i would like the scaled points to be e.g. blue

I thought that by using a simple if statement as shown below that,
in my crude way, it should work but all the points just assume the
color of 'else' condition i.e blue.

I am a total novice at matlab and I cannot see how to do this. any suggestions would be most helpful!

many thanks

--------------

%Random positions in x,y between 0 and 500
minp=0.;
maxp=500.;
xx=minp + (maxp -minp)*rand(1,500);
yy=minp + (maxp -minp)*rand(1,500);

%Random values for each x,y position
%between -300,300, which determine the size of the markers
%in the scatter plot
minv=-300.;
maxv=300.;
velx=minv + (maxv -minv)*rand(1,500);
S=(abs(velx)/10.);

if velx <. 0.
scatter(xx,yy,S,'MarkerFaceColor','red');
else
scatter(xx,yy,S,'MarkerFaceColor','blue');
end

----------------
From: Nic Roberts on
Hi,

Your problem is the "if velx<0" part. I have amended your code so that it cycles through each element one byone rather than checking the whole vector.

%Random positions in x,y between 0 and 500
minp=0.;
maxp=500.;
xx=minp + (maxp -minp)*rand(1,500);
yy=minp + (maxp -minp)*rand(1,500);

%Random values for each x,y position
%between -300,300, which determine the size of the markers
%in the scatter plot
minv=-300;
maxv=300;
velx=minv + (maxv -minv)*rand(1,500);
S=(abs(velx)/10.);

hold on
for i=1:500

if velx(i) < 0
scatter(xx(i),yy(i),S(i),'r','filled');
else
scatter(xx(i),yy(i),S(i),'b','filled');
end

end

Hope this helps

Nic

"RUSSELL " <r.johnston(a)physics.gla.ac.uk> wrote in message <i2bs6n$1i9$1(a)fred.mathworks.com>...
> In the following code what i want to achieve is the following using the scatter function (for now i am just testing with random data):
>
> 1. plot the x,y positions which have varying marker sizes depending
> on the absolute value of 'velx'
>
> I have gotten this to work by setting S=(abs(velx)/10.);
>
> 2. velx has a range in values from -300 to 300. So
> additionally i would like, for negative
> values i would like the scaled points to be e.g. red
> For postive values i would like the scaled points to be e.g. blue
>
> I thought that by using a simple if statement as shown below that,
> in my crude way, it should work but all the points just assume the
> color of 'else' condition i.e blue.
>
> I am a total novice at matlab and I cannot see how to do this. any suggestions would be most helpful!
>
> many thanks
>
> --------------
>
> %Random positions in x,y between 0 and 500
> minp=0.;
> maxp=500.;
> xx=minp + (maxp -minp)*rand(1,500);
> yy=minp + (maxp -minp)*rand(1,500);
>
> %Random values for each x,y position
> %between -300,300, which determine the size of the markers
> %in the scatter plot
> minv=-300.;
> maxv=300.;
> velx=minv + (maxv -minv)*rand(1,500);
> S=(abs(velx)/10.);
>
> if velx <. 0.
> scatter(xx,yy,S,'MarkerFaceColor','red');
> else
> scatter(xx,yy,S,'MarkerFaceColor','blue');
> end
>
> ----------------
From: RUSSELL on
Many thanks Nic!

That worked a treat and was so easy in the end!

You're a star!
cheers
Russ


"Nic Roberts" <dingtheking(a)googlemail.com> wrote in message <i2bund$aef$1(a)fred.mathworks.com>...
> Hi,
>
> Your problem is the "if velx<0" part. I have amended your code so that it cycles through each element one byone rather than checking the whole vector.
>
> %Random positions in x,y between 0 and 500
> minp=0.;
> maxp=500.;
> xx=minp + (maxp -minp)*rand(1,500);
> yy=minp + (maxp -minp)*rand(1,500);
>
> %Random values for each x,y position
> %between -300,300, which determine the size of the markers
> %in the scatter plot
> minv=-300;
> maxv=300;
> velx=minv + (maxv -minv)*rand(1,500);
> S=(abs(velx)/10.);
>
> hold on
> for i=1:500
>
> if velx(i) < 0
> scatter(xx(i),yy(i),S(i),'r','filled');
> else
> scatter(xx(i),yy(i),S(i),'b','filled');
> end
>
> end
>
> Hope this helps
>
> Nic
>
> "RUSS