How to draw vectors (physical 2D/3D vectors) in MATLAB?

后端 未结 6 471
一个人的身影
一个人的身影 2020-12-25 14:00

I want to know the simplest way to plot vectors in MATLAB. For example:

a = [2 3 5];
b = [1 1 0];
c = a + b;

I want to visualize this vect

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 14:15

    I agree with Aamir that the submission arrow.m from Erik Johnson on the MathWorks File Exchange is a very nice option. You can use it to illustrate the different methods of vector addition like so:

    • Tip-to-tail method:

      o = [0 0 0];  %# Origin
      a = [2 3 5];  %# Vector 1
      b = [1 1 0];  %# Vector 2
      c = a+b;      %# Resultant
      arrowStarts = [o; a; o];        %# Starting points for arrows
      arrowEnds = [a; c; c];          %# Ending points for arrows
      arrow(arrowStarts,arrowEnds);   %# Plot arrows
      
    • Parallelogram method:

      o = [0 0 0];  %# Origin
      a = [2 3 5];  %# Vector 1
      b = [1 1 0];  %# Vector 2
      c = a+b;      %# Resultant
      arrowStarts = [o; o; o];        %# Starting points for arrows
      arrowEnds = [a; b; c];          %# Ending points for arrows
      arrow(arrowStarts,arrowEnds);   %# Plot arrows
      hold on;
      lineX = [a(1) b(1); c(1) c(1)];  %# X data for lines
      lineY = [a(2) b(2); c(2) c(2)];  %# Y data for lines
      lineZ = [a(3) b(3); c(3) c(3)];  %# Z data for lines
      line(lineX,lineY,lineZ,'Color','k','LineStyle',':');  %# Plot lines
      

提交回复
热议问题