简体   繁体   English

MATLAB中2D矩阵中的可变长度行

[英]Variable length row in a 2D matrix in MATLAB

嗨,我需要在Matlab中存储可变长度的行。有人可以指向正确的方向吗?

I realized the link in my comment wasn't necessarily clear enough for this kind of question, so I thought I'd expand it to an answer with an example. 我意识到我的评论中的链接对于这类问题不一定清楚,所以我想我会用一个例子将它扩展为答案。

Using a cell array, you can hold any data type in each cell. 使用单元格数组,您可以在每个单元格中保存任何数据类型。 Less generally, this means it works for holding vectors of different lengths, which is what you're asking for. 不太常见,这意味着它适用于保持不同长度的矢量,这正是您所要求的。

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

#% assigning a variable into a cell array:
C{1} = A;  #% note the curly braces {} instead of ()
C{2} = B;

#% getting a value out of a cell array:
D = C{2}; #% D is a 1x2 matrix of doubles
E = C(2); #% E is a 1x1 cell

As you can see, to access the elements of a cell array, use curly brackets {} instead of the usual parentheses () , both for reading from/writing to the cell array. 如您所见,要访问单元格数组的元素,请使用大括号{}代替通常的括号() ,以便读取/写入单元格数组。

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

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