concatenate cell array of cell arrays

29 Ansichten (letzte 30 Tage)
Ghenji
Ghenji am 7 Jun. 2018
Bearbeitet: Stephen23 am 23 Feb. 2022
I have got this cell variable with 10 cell arrays. It is possible to horizontally concatenate them if the dimension is consistent but if not it gives me an error. How do i concatenate this cell arrays of unequal length?

Akzeptierte Antwort

Stephen23
Stephen23 am 7 Jun. 2018
Bearbeitet: Stephen23 am 23 Feb. 2022
  3 Kommentare
Stephen23
Stephen23 am 7 Jun. 2018
Bearbeitet: Stephen23 am 7 Jun. 2018
Note that you could vertically concatenate them without any problem, as they all have exactly one column.
If you really need to horizontally concatenate them you will need to pad their rows first so that they have the same number of rows: you could use a loop, or cellfun. Or just do something like this:
col = size(C,2);
row = cellfun('size',C,1);
out = cell(max(row),col);
for k = 1:col
out(1:row(k),k) = C{k};
end
Ghenji
Ghenji am 7 Jun. 2018
well well!! That worked. Thanks a lot Stephen.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rishabh Rathore
Rishabh Rathore am 7 Jun. 2018
Bearbeitet: Rishabh Rathore am 7 Jun. 2018
I'm assuming you want to retain the data of one cell array as a column.
A work around could be the following
  • Find the length of the longest cell array
  • append the empty cell to all the smaller cell arrays
  • finally concatenate them, you may use horzcat for horizontal concatenation.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by