简体   繁体   English

在Matlab中绘制3D点并通过线顺序连接它们

[英]Drawing 3D points in Matlab and connect them in order via line

I have an array that contains 3D float points. 我有一个包含3D浮点数的数组。 Not only I want to depict them in a figure but also I want to connect them with lines. 我不仅要在图形中描绘它们,而且想将它们与线连接起来。

Example) lets say we have array called X: 例如),假设我们有一个名为X的数组:

X=[0, 0, 0; 0.48, -0.88, 0.09; -1.06, 0.55, 0.9; -0.65, 1.5, -1.44; 1.1, 0.59,
-1.11;0.76, 0.86, -0.52; -1.08, -0.28, 0.55; 1.47, -1.21, 0.14; 1.42, -2.15, 0.71; -0.64,  
1.87, 2.4;2.32, -2.44, 2.02; 2.25, -2.56, -3.03; 2.35, 2.65, -1.5; 0.23, -2.25, 2.78; 2.47,  
-3.12,  -1.91; 2.27, 1.37, -3.05; 2.3, 1.9, -1.29; -1.77, -0.51, 2.33];  

    X1= [0,0,0]  
    X2=[0.48, -0.88, 0.09]  
    X3=[-1.06, 0.55, 0.9] ...   

now I want that X1...Xn to be drawn in figure as points then X1 get connected to X2, X2 get connected to X3, X3 get connected to X4, etc 现在我希望将X1 ... Xn绘制为点,然后将X1连接到X2,将X2连接到X3,将X3连接到X4,依此类推

how could I do that? 我该怎么办?

Here is what I ve done but I get a wrong figure: 这是我做过的事情,但我得到了错误的数字:

figure;hold on;  
    P=[];  
    for i=1:size(X,1)  
    x=X(i,1);  
    y=X(i,2);  
    z=X(i,3);  
    A=[ x,y,z];  
    P=vertcat(P,A);  
    plot(P);  
    end  

And Here is the output: 这是输出:

在此处输入图片说明

Check out the plot3 documentation . 查看plot3文档

In particular, plot3(X, Y, Z) will plot the points and join them with a line. 特别是, plot3(X, Y, Z)将绘制点并用线将它们连接起来。

In your case: 在您的情况下:

plot3(X(:, 1), X(:, 2), X(:, 3))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM