Asked by Ahmed Madhun
on 4 Sep 2019

I have a Matrix (M) that looks like this:

X Y Angle

20 30 200

30 100 100

80 450 50

How can i plot a point for each raw as a coordinate? and a short line that indicates the angle/diraction this node is facing.

Answer by Kelly Kearney
on 4 Sep 2019

Accepted Answer

With quiver, the u and v arguments represent the horizontal and vertical components of the arrow you want to draw. You can calculate those easily based on the angle:

dat =[...

20 30 200

30 100 100

80 450 50];

u = cosd(dat(:,3));

v = sind(dat(:,3));

plot(dat(:,1), dat(:,2), 'o');

hold on;

s = 0.1; % scaling factor, adjust as desired

quiver(dat(:,1), dat(:,2), u, v, s);

axis equal;

Ahmed Madhun
on 5 Sep 2019

That's exactly what i was looking for. Thanks!

Sign in to comment.

Answer by Neuropragmatist
on 4 Sep 2019

Edited by Neuropragmatist
on 4 Sep 2019

Your question is lacking some detail I suspect. Just to plot the XY data you could do this:

dat =[20 30 200

30 100 100

80 450 50];

figure

plot(dat(:,1),dat(:,2))

But my guess is that you are asking how you can plot lines starting at the XY coordinates with the angles listed in the third column? To do that you will have to choose a length of the lines and then you can do something like this:

% use dat from above

L = 100;

x2 = dat(:,1) + (L .* cosd(dat(:,3))); % use trigonometry to work out position of line 100 units from the starting point

y2 = dat(:,2) + (L .* sind(dat(:,3)));

figure

plot([dat(:,1) x2]',[dat(:,2) y2]')

daspect([1 1 1])

Hope this helps,

M.

Ahmed Madhun
on 4 Sep 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## darova (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/478890-plotting-x-y-cordintions-with-a-line-short-line-that-indicates-the-angle#comment_742176

## Ahmed Madhun (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/478890-plotting-x-y-cordintions-with-a-line-short-line-that-indicates-the-angle#comment_742227

Sign in to comment.