Plotting X, Y cordintions with a line short line that indicates the angle

4 次查看(过去 30 天)
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.
  2 个评论
Ahmed Madhun
Ahmed Madhun 2019-9-4
Didn't find any tool usful yet. I saw some ideas, where i can use quiver(), but this require a transfrom of the angel to be set as u and v (which i didn't know that they represent)

请先登录,再进行评论。

采纳的回答

Kelly Kearney
Kelly Kearney 2019-9-4
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;

更多回答(1 个)

Neuropragmatist
Neuropragmatist 2019-9-4
编辑:Neuropragmatist 2019-9-4
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.
  1 个评论
Ahmed Madhun
Ahmed Madhun 2019-9-4
Not really, i have a data set of coordinates (x and y) with represents a node. They also have a third variable which is the angle that i would like to represent, in order to see what this node is facing. i don't need to draw a full line between nodes, just something that can show me the direction of the node

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by