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

后端 未结 6 478
一个人的身影
一个人的身影 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:32

    I did it this way,

    2D

    % vectors I want to plot as rows (XSTART, YSTART) (XDIR, YDIR)
    rays = [
      1 2   1 0 ;
      3 3   0 1 ;
      0 1   2 0 ;
      2 0   0 2 ;
    ] ;
    
    % quiver plot
    quiver( rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ) );
    

    3D

    % vectors I want to plot as rows (XSTART, YSTART, ZSTART) (XDIR, YDIR, ZDIR)
    rays = [
      1 2 0  1 0 0;
      3 3 2  0 1 -1 ;
      0 1 -1  2 0 8;
      2 0 0  0 2 1;
    ] ;
    
    % quiver plot
    quiver3( rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ), rays( :,5 ), rays( :,6 ) );
    

    Based on the quiver and quiver3 documentation

提交回复
热议问题