필터 지우기
필터 지우기

How to plot 3 vectors but align them so that they are all originating from the same point?

조회 수: 2 (최근 30일)
example
a = [-2 3]
b = [3 7]
c = [-3 5]
Thanks
  댓글 수: 3
Jan
Jan 2017년 5월 14일
편집: Jan 2017년 5월 14일
What is "plotv"? How do you want the "vectors" to appear? All you provide are the location of 3 points in 2D.
Alex Vasin
Alex Vasin 2017년 5월 14일
I want 3 vectors all to start from the same point and go outwards. Apparently that's what plotv is supposed to do, but it only seems to allow for 2 vectors.
i.e. vectors all have direction, start point and end point. I want the plot to have all 3 vectors to have their start positions to be in the same point on the graph.

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

채택된 답변

Star Strider
Star Strider 2017년 5월 14일
This may do what you want. You will have to set the ‘startm’ row number in the repmat call to match the number of vectors you want to plot (here, 3). This code works for three vectors.
The Code
startv = [1 1]; % Starting Point
startm = repmat(startv, 3, 1);
a = [-2 3];
b = [3 7];
c = [-3 5];
abc = [a; b; c];
figure(1)
plot([startm(:,1) abc(:,1)]', [startm(:,2) abc(:,2)]')
grid
axis([-5 5 0 10])
The Plot
  댓글 수: 2
Alex Vasin
Alex Vasin 2017년 5월 15일
Thank you. I don't understand any of it, but I will use it anyway.
Star Strider
Star Strider 2017년 5월 15일
My pleasure.
I apologise for not explaining how it works.
The ‘startv’ is the (1x2) vector defining the start point for all the vectors. The ‘startm’ matrix duplicates it to form a (3x2) matrix to match the number of vectors (here 3) that you want to plot. (This is necessary for the plot arguments to agree.)
The ‘abc’ matrix is a vertical concatenation of the three vectors you defined. Creating these matrices makes the code easier to write.
The plot arguments themselves require a bit of explaining. The plot function requires a vector of points for each (x,y) pair (line plotted), so the x vectors for each are the x coordinate of your start point horizontally concatenated with the x coordinate of ‘abc’. The y vectors are defined similarly from the y coordinate of the start point and the y coordinates of ‘abc’. This creates two (3x2) matrices as arguments to plot. So it plots from the x value of the start point and the x value of the ‘abc’ vectors to the y values of the start point and ‘abc’ vectors, defined similarly.
Through the magic of the way plot works, this plots the individual lines.
If you have any further questions about it, post back here and I will do my best to explain it, and if necessary change it if you want the lines plotted differently.

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

추가 답변 (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