25 views (last 30 days)

Hi,

I have a set of stations coordinates in a text file. The stations coordinates consist of positions of 2 points (X1, Y1) and (X2, Y2) at 50 stations. How do I plot/visualize the magnitude and direction of the stations coordinate to see the the changes in distance and direction?

Basically I want the plot to look like this [x1, y1]--------->[x2, y2] (with correct magnitude and direction) but for 50 stations.

I have tried the function quiver, but still cannot plot all the 50 stations.

Can somebody show me how to plot the magnitude and direction for 50 stations?

Thank you.

darova
on 9 Dec 2019

Edited: darova
on 9 Dec 2019

try this (not tested)

data = load ('Input.txt');

[row, col] = size (data);

Y2 = data (:,1);

X2 = data (:,2);

Y1 = data (:,3);

X1 = data (:,4);

delta_X = X2 - X1;

delta_Y = Y2 - Y1;

magnitude = sqrt(((delta_X).^2)+((delta_Y).^2));

cm = jet(50); % create colormap

ind = 1 + round(magnitude/max(magnitude)*49); % convert magnitude to index

plot(0,0)

hold on

for i = 1:length(X1)

quiver(X1(i),Y(i),delta_X(i),delta_Y(i),'color',cm(ind(i)))

end

hold off

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/495631-how-to-plot-magnitude-and-directions-between-2-points#comment_776059

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/495631-how-to-plot-magnitude-and-directions-between-2-points#comment_776059

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/495631-how-to-plot-magnitude-and-directions-between-2-points#comment_776182

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/495631-how-to-plot-magnitude-and-directions-between-2-points#comment_776182

Sign in to comment.