Concatenating cell arrays with a different number of columns
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sumara
am 13 Jun. 2019
Kommentiert: Guillaume
am 16 Mär. 2020
I have a 64x1 cell array that looks like this, I would like to vertically concatenate the cells in this array, and pad the rows with less columns with zeros
0 Kommentare
Akzeptierte Antwort
Guillaume
am 13 Jun. 2019
Bearbeitet: Guillaume
am 13 Jun. 2019
maxcols = max(cellfun('size', NonC_tRNAs, 2)); %get the number of columns of the widest array
padded = cellfun(@(m) [m, zeros(size(m, 1), maxcols - size(m, 2))], NonC_tRNAs, 'UniformOutput', false); %pad each array
NonC_tRNAs_Reference = vertcat(padded{:})
7 Kommentare
mmfjerstad
am 16 Mär. 2020
Sorry if this is a dumb question, but what is "m" in this instance?
padded = cellfun(@(m) [m, zeros(size(m, 1), maxcols - size(m, 2))], NonC_tRNAs, 'UniformOutput', false); %pad each array
Guillaume
am 16 Mär. 2020
" what is "m" in this instance?"
An arbitrary name for the input variable of the anonymous function called by cellfun. It will be in turn each element of the same array.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices 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!