Vertically Concatenate Cells with Same Number of Columns

I have a column of cells (column_data.png) with different number of rows but same number of columns. The cells contain numbers only. How can I vertically concatenate the cells in column_data?

 채택된 답변

Star Strider
Star Strider 2015년 7월 14일
I’m not sure what you want. Does this work for you?
data_final = { {rand(1,5)}; {rand(2,5)}; {rand(3,5)} };
data_cat = cellfun(@vertcat, data_final);

댓글 수: 2

The data_start is the starting cell array that I have and the data_final is the vertically concatinated cell array that I would like to have. I am afraid the code you suggested does not work in this case.
I needed a loop, but this works:
DF = {};
for k1 = 1:length(data_start)
if ~isempty(data_start{k1})
DF = vertcat(DF, data_start{k1});
end
end
Here, ‘DF’ is ‘data_final’. I didn’t want to overwrite it so I could check it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 14일
편집: Azzi Abdelmalek 2015년 7월 14일
cell2mat(YourCellArray)
Or Maybe your data looks like
a={num2cell(rand(2,3));num2cell(rand(1,3));num2cell(rand(4,3))};
out=cell2mat(cellfun(@(x) cell2mat(x),a,'un',0))

댓글 수: 2

Eli Dim
Eli Dim 2015년 7월 14일
편집: Eli Dim 2015년 7월 14일
The first option does not work because I have cells inside.
I want to do the equivalent of:
vertcat(data_final{1,1},data_final{2,1},data_final{3,1},data_final{4,1},....data_final{lastrow,1})
I want to keep the cells and not convert them using cell2mat
a={num2cell(rand(2,3));num2cell(rand(1,3));num2cell(rand(4,3))}
b=cat(1,a{:})

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2015년 7월 14일

댓글:

2015년 7월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by