简体   繁体   English

MATLAB中的单元阵列

[英]Cell arrays in MATLAB

I know what a cell array is. 我知道什么是cell array I just came to the following line: 我刚刚来到以下几行:

cell_array = cell([], 1);

What does that mean? 这意味着什么? How can we read the above line? 我们怎样才能阅读上述内容?

Thanks. 谢谢。

So this makes a 0x1 empty cell array. 所以这会产生一个0x1空单元格数组。 As in literally 0 rows and 1 column. 如字面上的0行和1列。 You could make a 0x0 cell array like this: 你可以像这样制作一个0x0单元格数组:

cell_array = {}

which makes sense to me. 这对我来说很有意义。 I do that sometimes like if you can't preallocate before a loop, sometimes it's useful to concatenate onto or to go cell_array(end) = ... in the loop. 我有时会这样做,如果你不能在一个循环之前预分配,有时在循环中连接到或转到cell_array(end) = ...是有用的。

I really don't know why you'd prefer a 0x1 but this question shows how it differs from a 0x0. 我真的不知道为什么你更喜欢0x1,但这个问题显示它与0x0的区别。 So I mean, if for some weird reason you are running a for loop on this empty array you know it will run at least once :/ But that's really scraping the barrel for a reason. 所以我的意思是,如果由于一些奇怪的原因你在这个空数组上运行一个for循环,你知道它至少会运行一次:/但是这真的是刮掉桶的原因。 I think just stick with = {} . 我认为坚持使用= {}

EDIT: 编辑:

As @radarhead points out, this is one way to preset the number of columns if you plan on concatenating new rows in a loop. 正如@radarhead指出的那样,如果您计划在循环中连接新行,这是预设列数的一种方法。

cell is used to allocate a cell array, in this case: cell_array . cell用于分配单元数组,在本例中为: cell_array

So an empty cell of size 0x1 is allocated. 因此分配了大小为0x1的空单元格。 However, this is no usefull syntax for cells. 但是,这对于单元格来说没有用处。 For other (custom) objects it can be useful to generate such empty arrays 对于其他(自定义)对象,生成这样的空数组会很有用

myArray = myObject.empty(0, 1);

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

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