MATLAB plot 画多条线段的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/seamanj/article/details/84981594

不管怎样, 逗号分开的是维度, 所以数据的排列只考虑一维即可, 其他照搬

对于数据

[ a 11 a 12 a 13 a 21 a 22 a 23 ] \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \end{bmatrix}

先竖着每 维画线段, 然后 下一个column作 为新的线段 , 所以线段 为

a 11 a_{11} a 21 a_{21}
a 12 a_{12} a 22 a_{22}
a 13 a_{13} a 23 a_{23}

A= [0 0 ;
    1 0 ;
    1 1 ];
B = [0 1 ;
    1 2;
    2 1 ];

hold on;
% plot([A(1,1) B(1,1)] , [ A(1,2) B(1,2) ] );
% plot([A(2,1) B(2,1)] , [ A(2,2) B(2,2) ] );
% plot([A(3,1) B(3,1)] , [ A(3,2) B(3,2) ] );

plot([A(:,1) B(:,1)]', [A(:,2) B(:,2)]');

% camproj('perspective');
 axis square; 
% axis off;
% hold on;

在这里插入图片描述

如果是这样的数据
[ a 11 a 12 a 21 a 22 a 31 a 32 ] \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \\ a_{31} & a_{32} \end{bmatrix}
那么 就是线段
a 11 a_{11} a 21 a_{21}
a 21 a_{21} a 31 a_{31}
a 12 a_{12} a 22 a_{22}
a 22 a_{22} a 32 a_{32}

A= [0 0 ;
    1 0 ;
    1 1 ];
B = [0 1 ;
    1 2;
    2 1 ];

hold on;
% plot([A(1,1) B(1,1)] , [ A(1,2) B(1,2) ] );
% plot([A(2,1) B(2,1)] , [ A(2,2) B(2,2) ] );
% plot([A(3,1) B(3,1)] , [ A(3,2) B(3,2) ] );

plot([A(:,1) B(:,1)], [A(:,2) B(:,2)]);

% camproj('perspective');
 axis square; 
% axis off;
% hold on;

在这里插入图片描述

可以看到是四条线段

猜你喜欢

转载自blog.csdn.net/seamanj/article/details/84981594
今日推荐