Vertically concatenate part of cell contents

In MatLab, all cells in my 60x1-cellarray contain a 10x1 double.

I would like to concatenate all these doubles vertically, except for the first number in every double.

My failed attempts was:

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

This, obviously, did not work becauce CellArray{:,1} refers to multiple cells so that (2:end) is a bit silly.

Do you have any suggestions?

Thanks in advance!

Answers


Why not just do it in two lines:

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

Try this -

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

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

Okay. I found a workaround. Just delete that first double after contacenating everything. Not pretty but it works...

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

Thanks for your help!


There is this one-line solution where selection is done before concatenation

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

Input & output

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

ans =

     2
     3
     4
     2
     3
     4
     2
     3
     4

Need Your Help

Strange animation when moving last row out of section and deleting section

iphone objective-c ios uitableview

I have a multi-section tableview. In edit mode I allow rows to be moved from one section to another. Once the final row is removed from one section I delete that section. So I am using deleteSect...

Open-source Python tools for text detection

python text machine-learning neural-network ocr

Are there are any open-source projects that can be used to detect whether an image has text? It doesn't need to do OCR, just tell us whether there is a good probability that the image has text on i...