Reputation: 13
There is a cell with five arrays. Each array consits of two rows and 30 columns. Now i want one array with the values in the first rows of the arrays merged.
cellC{1,1} = arrayA1 = [1 2 3; 4 5 6]
cellC{1,2} = arrayA2 = [11 12 13; 14 15 16]
....
I want to get the array
[1 2 3 11 12 13]
Indexing like the following does not work:
cellC{1, 1:5}(1,:)
I thought of a for-loop but there must be a simpler solution. I hope you can help me. Thank you very much!
Upvotes: 1
Views: 297
Reputation: 65460
You can utilize {:}
indexing to create a comma separated list that you can then pass to cat
to concatenate all of the cell contents horizontally. You can then select out the first row from the resulting matrix.
tmp = cat(2, cellC{:});
result = tmp(1,:);
Upvotes: 1