Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
I would like to show particle positions and velocities

Subject: I would like to show particle positions and velocities

From: Ke

Date: 30 Jan, 2009 13:53:02

Message: 1 of 7

HI all,

I am doing particle transport experiment currently and I have the particle positions and velocities as 4 one-Dimensional arrays x,y,vx,vy where x , y represents the positions and vx,vy the velocities. I am using plot(X1,Y1,'*') to show the positions and I would like to show the velocities arrow in the same plot. After failing trying quiver myself, I am expecting some suggestions from experienced people here. BTW: i am rookie, any comments and suggestions would be welcome and appreciated.

thx in advance

Jayson

Subject: I would like to show particle positions and velocities

From: Steven Lord

Date: 30 Jan, 2009 14:22:09

Message: 2 of 7


"Ke " <dustyplasma@gmail.com> wrote in message
news:glv0nu$9lj$1@fred.mathworks.com...
> HI all,
>
> I am doing particle transport experiment currently and I have the particle
> positions and velocities as 4 one-Dimensional arrays x,y,vx,vy where x ,
> y represents the positions and vx,vy the velocities. I am using
> plot(X1,Y1,'*') to show the positions and I would like to show the
> velocities arrow in the same plot. After failing trying quiver myself, I
> am expecting some suggestions from experienced people here. BTW: i am
> rookie, any comments and suggestions would be welcome and appreciated.

QUIVER would probably be the first thing I tried. You said that you tried
QUIVER but failed -- does the example on the reference page work for you?

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quiver.html

Note that the HOLD ON call in the example is important, otherwise the QUIVER
plot will replace your previous plot.

--
Steve Lord
slord@mathworks.com

Subject: I would like to show particle positions and velocities

From: Ke

Date: 30 Jan, 2009 14:49:02

Message: 3 of 7


> QUIVER would probably be the first thing I tried. You said that you tried
> QUIVER but failed -- does the example on the reference page work for you?
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quiver.html
>
> Note that the HOLD ON call in the example is important, otherwise the QUIVER
> plot will replace your previous plot.
>
> --
> Steve Lord
> slord@mathworks.com
>

Dear Steve,

What I have tried is something like this

[XX,YY]=meshgrid(x,y');
[VX,VY]=meshgrid(vx,vy');

% Create plot
plot(X1,Y1,'MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[0 0 0],...
    'MarkerSize',10,...
    'Marker','o',...
    'LineStyle','none');

hold on
axis square
quiver(XX,YY,VX,VY,5);

However, 'quiver ' plot velocity vector in every meshgrid cross seccion instead of starting from the particles which plotted based on thier positions. Could you please tell me how should I modify this code to get exactly velocity vector starting from the corresponding particles.

many thanks

Jayson

Subject: I would like to show particle positions and velocities

From: Steven Lord

Date: 30 Jan, 2009 15:18:48

Message: 4 of 7


"Ke " <dustyplasma@gmail.com> wrote in message
news:glv40u$hnd$1@fred.mathworks.com...
>
>> QUIVER would probably be the first thing I tried. You said that you
>> tried
>> QUIVER but failed -- does the example on the reference page work for you?
>>
>> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quiver.html
>>
>> Note that the HOLD ON call in the example is important, otherwise the
>> QUIVER
>> plot will replace your previous plot.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>>
>
> Dear Steve,
>
> What I have tried is something like this
>
> [XX,YY]=meshgrid(x,y');
> [VX,VY]=meshgrid(vx,vy');
>
> % Create plot
> plot(X1,Y1,'MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[0 0 0],...
> 'MarkerSize',10,...
> 'Marker','o',...
> 'LineStyle','none');
>
> hold on
> axis square
> quiver(XX,YY,VX,VY,5);
>
> However, 'quiver ' plot velocity vector in every meshgrid cross seccion
> instead of starting from the particles which plotted based on thier
> positions. Could you please tell me how should I modify this code to get
> exactly velocity vector starting from the corresponding particles.

Your PLOT call uses X1 and Y1 as the variables being plotted. Your QUIVER
call uses XX and YY as the locations from which the quiver arrows should
start. You didn't show how X1 and Y1 are defined, so I have no idea how
those variables are related to XX and YY.

--
Steve Lord
slord@mathworks.com

Subject: I would like to show particle positions and velocities

From: Ke

Date: 30 Jan, 2009 15:33:01

Message: 5 of 7

sry for those confusing typo.

 it should be like this

---------------------------------------------------
[XX,YY]=meshgrid(x,y');
[VX,VY]=meshgrid(vx,vy);

plot(x,y,'o');

hold on
axis square
quiver(XX,YY,VX,VY,5);
--------------------------------------------------
Note here X1,Y1 are the particle positions and vx ,vy are the corresponding velocities.

Subject: I would like to show particle positions and velocities

From: Thomas Clark

Date: 30 Jan, 2009 16:00:19

Message: 6 of 7

I suspect you might be confused about meshgrid. If you want velocity arrows to be plotted where your data points are, and if your data points are scattered arbitrarily, this is what you want. Copy the whole lot into a blank m-file then run it - you'll see what I mean:


% Test script to demonstrate how to use quiver on scattered data

% Generate some test data. Here, we'll use 100 points (say) in two
% dimensions, and assign a velocity at each point (arbitrary velocity field)
pos_x = rand(100,1);
pos_y = rand(100,1);
u_vel = 20*pos_x + 0.1;
v_vel = 20*pos_y.*pos_x + 0.1;


% Set up a figure to plot into...
figure()


% Plot the particle positions:
axes()
plot(pos_x,pos_y,'go')
hold on

% Plot the velocity arrows:
quiver(pos_x, pos_y, u_vel, v_vel)
grid on
xlim([0 1])
ylim([0 1])
zlim([0 1])

title('Quiver using scattered data')

Subject: I would like to show particle positions and velocities

From: Ke

Date: 2 Feb, 2009 08:56:01

Message: 7 of 7

it works.

Thanks you, Thomas.


"Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <glv86i$sep$1@fred.mathworks.com>...
> I suspect you might be confused about meshgrid. If you want velocity arrows to be plotted where your data points are, and if your data points are scattered arbitrarily, this is what you want. Copy the whole lot into a blank m-file then run it - you'll see what I mean:
>
>
> % Test script to demonstrate how to use quiver on scattered data
>
> % Generate some test data. Here, we'll use 100 points (say) in two
> % dimensions, and assign a velocity at each point (arbitrary velocity field)
> pos_x = rand(100,1);
> pos_y = rand(100,1);
> u_vel = 20*pos_x + 0.1;
> v_vel = 20*pos_y.*pos_x + 0.1;
>
>
> % Set up a figure to plot into...
> figure()
>
>
> % Plot the particle positions:
> axes()
> plot(pos_x,pos_y,'go')
> hold on
>
> % Plot the velocity arrows:
> quiver(pos_x, pos_y, u_vel, v_vel)
> grid on
> xlim([0 1])
> ylim([0 1])
> zlim([0 1])
>
> title('Quiver using scattered data')

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us