Vertically Concatenate Cells with Same Number of Columns
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eli Dim
am 14 Jul. 2015
Kommentiert: Star Strider
am 14 Jul. 2015
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?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 14 Jul. 2015
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 Kommentare
Star Strider
am 14 Jul. 2015
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.
Weitere Antworten (1)
Azzi Abdelmalek
am 14 Jul. 2015
Bearbeitet: Azzi Abdelmalek
am 14 Jul. 2015
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 Kommentare
Azzi Abdelmalek
am 14 Jul. 2015
a={num2cell(rand(2,3));num2cell(rand(1,3));num2cell(rand(4,3))}
b=cat(1,a{:})
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!