Question

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. Each cell is a single row vector with around 7500 values or columns, hence them being 1x7500 or so.

I want to concatenate those 15 cells in the array into a single vector. The resulting vector will be around 1x112500 (I just want to piece the ends of the cells together). I don't think horzcat is helping, since horzcat(myarray) just makes an identical cell array.

Thanks in advance!

Was it helpful?

Solution

First you expand your cell doing myCell{:}, this will create a comma separated list from your cell contents. Afterwards you merge them using brakets [myCell{:}] if you want to merge as a line vector. 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(myCell)

ans =

     1     2     3     4     5     6     7     8
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top