Plot a line between two points with given angle which points its direction.
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I need your guidance that how I can compute angle between two points and draw a direction vector to get the direction of these two colored lines(Pink,Blue) at each instant of time.
Secondly is it possible that I can extract the speed as I am given (x,Y) position and time (as can be seen from the figure which is plotted on X,Y plane in a given time)?
Thanks in advance for your kind reply.

採用された回答
Star Strider
2015 年 12 月 21 日
8 件のコメント
Using quiver I have got this graph, using quiver [x,y,u,v] and i know the x and y position of start and end of direction vector for a node but how I can get the value of node position in the middle of a vector. It will be (x2-x1/u,y2-y1/v) or something different?

I don’t know what you mean by ‘the value of node position in the middle of a vector’. You would have to know one value (either x or y) to get the other. If you have two specific (x,y) points and you want an equation for a line connecting them, the easiest way would be to use the polyfit and polyval functions and the known x-value between them:
b = polyfit([x1, x2], [y1, y2], 1);
y3 = polyval(b, x3);
such that ‘x3’ here is between ‘x1’ and ‘x2’ (that is, x1 < x3 < x2).
Star Strider, Thanks for your kind reply.
I have attached my code file so you will better get idea about my code. I want to find the position of a node at any instant of time when i just run this simulation it give me minimum distance from other node and its own position at that time instant.

You have four variables each (1x501) vectors. Your time variable is a (7x1) double, so doing anything with respect to that time vector is not going to work. You could get time from the position differences and the velocities, but I am lost as to what you want to do. Plotting ‘v_x’ and ‘v_y’ is straightforward and produces 5 straight lines.
I have no idea what you want to do, but I took a wild guess and came up with this:
D = load('Arsal15 node_property.mat');
np = D.node_property;
x = np.v_x;
y = np.v_y;
vx = np.vel_x;
vy = np.vel_y;
xp = gradient(x); % X-Position Change
yp = gradient(y); % Y-Position Change
vt = hypot(vx(:), vy(:)); % Net Velocity
pt = hypot(xp, yp); % Net Position Change
tv = pt(:)./vt(:); % Differential Time
tc = cumsum(tv); % Cumulative Time
figure(1)
plot3(x, y, tc, '-r')
hold on
quiver3(x(:), y(:), tc(:), xp(:), yp(:), tv(:), 1.5, 'LineWidth',1)
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Time')
figure(2)
plot3(x, y, tc, '.r')
hold on
quiver3(x(:), y(:), tc(:), xp(:), yp(:), tv(:), 2.5, 'LineWidth',1)
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Time')
Thanks for your time and kind reply Star Strider.
Actually I want to do three things
Regarding time I can use interpolation like this so all index will be (1x51).
if true
node_property(nodeIndex).time = interp1(s_mobility.VS_NODE(nodeIndex).V_TIME,v_t);
end
1) .Getting data from the structure in a efficient way so that I use one loop index and I get data of all mobile nodes in their variable like x_position, y_position x_velocity, y_velocity using single for loop.
2). I want the position of mobile node at any instant of time like if I call a function
if true
[x,y] = node_position(node_number,time_instant,direction);
end
it gives times position of that node at that time instant but also direction vector value.
3). I want to calculated distance of node1(x,y) with node2(x,y) I am using function
if true
distance = findSqDistance(node1_X,node1_Y,node2_X,node2_Y);
end
but I am fail to pass array of (1x51) of x and y of node1 and node 2 to this function and get a result back in distance matrix which also a (1x51) so I m stuck. Actually i get puzzled in indexing.
My pleasure.
I have no idea what you’re doing. I gave my best guess, and that’s all I can do. Your ‘nodes’ simply look like points on the trajectory of something, and beyond plotting them as I did, I really cannot help further.
Thanks for your guidance.
My pleasure.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
