Concatenate part of the cell content vertically

In MatLab, all the cells of my 60x1-cellarray contain 10x1 double.

I would like to combine all these doubles vertically, with the exception of the first number in each double.

My unsuccessful attempts:

CellArray={[1 2 3];[1 2 3];[1 2 3]}
ContacenatedCellArray = vertcat(CellArray{:,1}(2:end))

This obviously didn’t work, because it CellArray{:,1}applies to several cells, so it’s a (2:end)little stupid.

Do you have any suggestions?

Thanks in advance!

+4
source share
4 answers

Why not just do it in two lines:

temp = vertcat(CellArray{:}); %// or cell2mat(CellArray)
temp2 = temp(:,2:end)';
ContacenatedCellArray = temp2(:);
+3
source

Try it -

%%// Vertically concatenated array
ContacenatedCellArray = cell2mat(CellArray); 

%%// Use the first index of every double array to remove those
ContacenatedCellArray(1:10:end)=[]; 
+2
source

. . . , ...

ContacenatedCellArray(1:length(CellArray{1,1}):end)=[];

!

+2

,

cell2mat(arrayfun(@(x) x{1}(2:end), CellArray, 'UniformOutput', 0))

CellArray={(1:4)';(1:4)';(1:4)'}

ans =

     2
     3
     4
     2
     3
     4
     2
     3
     4
0

Source: https://habr.com/ru/post/1531336/


All Articles