matlab - cell2mat: padding using NaNs -
working in 2 dimensions cell arrays familiar topic you:
a{1,1}=rand(5,1); a{2,1}=rand(10,1); b=cell2mat(a); size(b)
the output of size of [15 1]
. find example outcome more useful:
0.150 0.340 0.610 0.190 0.740 nan nan nan nan nan 0.240 0.920 0.270 0.770 0.190 0.290 0.090 0.580 0.680 0.550
is there generalized way of padding cellarrays nans (in similar way above) can converted matrices easily?
as there lot of confusion here's graphically (please excuse handdrawing skills) mean, 1,2 depict cell arrays , 3 nan padding. 1,2,3 combined hould convertable matrix.
% find long vector islong=(length(a{2,1})>length(a{1,1}))+1; isshort=setdiff([1 2],islong); % result b=[a{islong,1} [a{isshort,1};nan(length(a{islong,1})-length(a{isshort,1}),1)]] b = 0.0796 0.6440 0.7326 0.4967 0.5137 0.9919 0.5223 0.7241 0.8144 0.3799 0.8346 nan 0.9469 nan 0.4866 nan 0.1802 nan 0.1786 nan
Comments
Post a Comment