How to plot magnitude and directions between 2 points?

조회 수: 24 (최근 30일)
Adilla Zulkifli
Adilla Zulkifli 2019년 12월 9일
댓글: Adilla Zulkifli 2019년 12월 10일
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.
  댓글 수: 2
darova
darova 2019년 12월 9일
Can you attach your attempts? And how do you want magnitude and direction to look like?
Adilla Zulkifli
Adilla Zulkifli 2019년 12월 9일
Attached is the input file in text file format. I would like to have Point 1A (X2, Y2) with magnitude and direction towards Point 1B (X1, Y1) which looks like an arrow. But the total of points I have are 50. So basically, the plot is supposed to have 50 arrows with magnitude and direction.
I have already tried using this coding but it doesn't work ;
data = load ('Input.txt');
[row, col] = size (data);
Y2 = data (:,1);
X2 = data (:,2);
Y1 = data (:,3);
X1 = data (:,4);
format long
delta_X = X2 - X1;
delta_Y = Y2 - Y1;
magnitude = sqrt(((delta_X).^2)+((delta_Y).^2));
format short
direction = wrapTo360(radtodeg(atan2(delta_X,delta_Y)));
P1 = [X2 Y2];
P2 = [X1 Y1] ;
DP = P2-P1;
figure(1)
quiver(P1(1),P1(2),DP(1),DP(2),0)
grid

댓글을 달려면 로그인하십시오.

채택된 답변

darova
darova 2019년 12월 9일
편집: darova 2019년 12월 9일
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
  댓글 수: 5
darova
darova 2019년 12월 10일
Look HERE
Adilla Zulkifli
Adilla Zulkifli 2019년 12월 10일
Yes. I already did that. Thank you again :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by