MATLAB: Create a Matrix from different ccella array.

cellmatrix

I have a cell array "data" 1×3 cell, each cell having different number of elements with 4 columns. for example data= [13252*4 double];[1516*4] double;[1244*4]double.
Now, I need a matrix which has maximum number of columns equal to 12 (sum of single columns) and rows equal to the maximum number of columns of all the cells. and I want to insert Nan when there is not value.
Thank you so much!!!

Best Answer

A{1} = rand(10,4) ;
A{2} = rand(5,4) ;
A{3} = rand(6,4) ;
% Get length of each cell
L = cellfun(@length,A) ;
for i = 1:length(L)
if size(A{i},1) < max(L)
T = NaN(max(L),4) ;
T(1:L(i),:) = A{i} ;
A{i} = T ;
end
end
iwant = [A{:}] ;