简体   繁体   English

Matlab:绘制存储为一列的x,y,z值

[英]Matlab: Plotting x, y, z values stored as one column

How should I accomplish this plotting task task in Matlab? 如何在Matlab中完成此绘图任务

Thank you. 谢谢。

EDIT: What I am asking is how to plot in Matlab when the data are in one column as described in the link given above. 编辑:我要问的是当数据在上面给出的链接所述的一列中时,如何在Matlab中进行绘制。

Regards, 问候,

ikel 伊克尔

You could reshape and transpose the matrix and extract the columns: 您可以reshape和转置矩阵并提取列:

vec = [1 2 3 4 5 6 7 8 9 10 11 12]';
reshaped_mat = reshape(vec,3,[])';

reshaped_mat will end up looking like this: reshaped_mat将最终看起来像这样:

 1     2     3
 4     5     6
 7     8     9
10    11    12

And you can extract the columns as follows: 您可以按以下方式提取列:

x = reshaped_mat(:,1);
y = reshaped_mat(:,2);
z = reshaped_mat(:,3);

You can try something like this > 您可以尝试这样的事情>

For example : A=[1 2 3; 例如:A = [1 2 3; 4 5 6;7 8 9] 4 5 6; 7 8 9]

A' would be A'将是

     1     4     7
     2     5     8
     3     6     9

First take the transpose, 首先换位

B = A'

And convert it into a single column, 并将其转换为单列,

B(:) would give B(:)会给

ans =

     1
     2
     3
     4
     5
     6
     7
     8
     9

Hope it helps 希望能帮助到你

yet another option for the lazy user: given a vector v 懒用户的另一个选择:给定向量v

 v = [1 2 3 4 5 6 7 8 9 10 11 12];

since we know the elements go like [x1,y1,z1,x2,y2,z2,...] , plotting x,y,z will probably require plot3 , so this is how it can be done directly: 由于我们知道元素像[x1,y1,z1,x2,y2,z2,...] ,绘制x,y,z可能需要plot3 ,因此可以直接这样做:

 plot3(v(1:3:end),v(2:3:end),v(3:3:end)) 

where the entries are equivalent to 条目等同于

 x=v(1:3:end);
 y=v(2:3:end);
 z=v(3:3:end);

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

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