# I want to plot current data (direction and magnitude) as vectors in a single plot

49 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (1)

Mathieu NOE
on 26 Oct 2020

hello Heidi

below some code with quiver vs feather display. depneds of your preferences - seem I got better angular rendering with quiver.

also note that I have dispayed only the first 100 samples to get a better picture to show the differences in rendering

I have manually added a baseline to the standard quiver display - so at the end it's very similar to what feather do;

you can of course remove that

hope it helps

Mathieu

load data.mat

% data file content :

% Name Size Bytes Class Attributes

%

% MX 4888x1 39104 double

% dir_adp3_mx 4888x1 39104 double

% mag_adp3_mx 4888x1 39104 double

% quiver(X,Y,U,V) plots velocity vectors as arrows with components (u,v)

% at the points (x,y). The matrices X,Y,U,V must all be the same size

% and contain corresponding position and velocity components (X and Y

% can also be vectors to specify a uniform grid). quiver automatically

% scales the arrows to fit within the grid.

% we need to create the X and Y coordinates of each vector

% NB : current direction (dir_adp3_mx) is in degrees

direction_rad = pi/180*dir_adp3_mx;

Xvec= mag_adp3_mx.*cos(direction_rad);

Yvec= mag_adp3_mx.*sin(direction_rad);

% create x,y points for quiver % quiver(X,Y,U,V) plots velocity vectors

% as arrows with components (u,v) at the points (x,y).

time = MX-MX(1); % so x start at 0 (needed ?)

y = zeros(size(x)); % base line

samples = 100; % to remove if necessary

%

figure(1)

quiver(time(1:samples),y(1:samples),Xvec(1:samples),Yvec(1:samples),'.');

% add central line

hold on

plot(time(1:samples),y(1:samples));

hold off

% quiver(...,LINESPEC) uses the plot linestyle specified for

% the velocity vectors. Any marker in LINESPEC is drawn at the base

% instead of an arrow on the tip. Use a marker of '.' to specify

% no marker at all. See PLOT for other possibilities.

figure(2)

feather(Xvec(1:samples),Yvec(1:samples))

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!