MATLAB: Concatenating cell arrays with a different number of columns

concatenateMATLABpadcolumnsvertical

I have a 64×1 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 blah.PNG

Best Answer

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{:})
Related Question