"Matt Fig"
> Here is another loop solution, though us showed a vectorized one (for very large cell arrays, the loop *might* be faster)...
...as had to BE expected, the looper runs MUCH faster...
% the data
nr=100; % #runs
cs=1000; % #cell rows
mc=10; % max #col/row
m=cell(cs,1);
m=cellfun(@(x) 1:ceil(mc*rand),m,'uni',false);
% the solutions
% 1) matt fig
a=m;
tic;
for i=1:nr
lns=cellfun(@length,a);
mt=zeros(numel(a),max(lns));
for ii = 1:numel(a)
mt(ii,1:lns(ii)) = a{ii};
end
end
t1=toc;
r1=mt;
% 2) us
tic;
for i=1:nr
nz=max(cellfun(@numel,m));
r2=cell2mat(cellfun(@(x) [x,zeros(1,nznumel(x))],m,'uni',false));
end
t2=toc;
% the result
disp(sprintf('%10.7f\n',isequal(r1,r2),t1,t2,100*t1/t2));
%{
% wintel system
% ic2/2*2.6ghz/2gb/winxp.sp3/r2008b
1.0000000 % res are equal
0.2894584 % matt fig
1.1760158 % us
24.6134762 % gain
%}
us
