[英]How to concatenate a cell array (15 cells in an array, each are around 1x7500)
This is probably one of this simplest questions, so it's likely been asked already, but I couldn't find any questions that were as simple as this one (they were all more complicated issues dealing with concatenation). 这可能是最简单的问题之一,因此很可能已经被问过了,但是我找不到任何像这个一样简单的问题(它们都是处理连接的更复杂的问题)。
I have cell array with 15 cells. 我有15个细胞的细胞阵列。 Each cell is a single row vector with around 7500 values or columns, hence them being 1x7500 or so. 每个单元格是单行向量,具有大约7500个值或列,因此它们是1x7500左右。
I want to concatenate those 15 cells in the array into a single vector. 我想将数组中的15个单元连接成一个向量。 The resulting vector will be around 1x112500 (I just want to piece the ends of the cells together). 得到的矢量大约是1x112500(我只想将细胞的末端拼凑在一起)。 I don't think horzcat is helping, since horzcat(myarray) just makes an identical cell array. 我不认为horzcat有帮助,因为horzcat(myarray)只是制作一个相同的细胞阵列。
Thanks in advance! 提前致谢!
First you expand your cell doing myCell{:}
, this will create a comma separated list from your cell contents. 首先,使用myCell{:}
扩展单元格,这将从单元格内容中创建一个逗号分隔的列表 。 Afterwards you merge them using brakets [myCell{:}]
if you want to merge as a line vector. 然后,如果要合并为线矢量,则使用brakets [myCell{:}]
合并它们。 I think this is the easiest way of doing what you want… 我认为这是做你想做的最简单的方法......
>> myCell = {[1 2 3], [4 5 6], [7 8]}
>> [myCell{:}]
ans =
1 2 3 4 5 6 7 8
Another alternative is cell2mat
: 另一种选择是cell2mat
:
>> cell2mat(myCell)
ans =
1 2 3 4 5 6 7 8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.