MATLAB says that "{A{I}} can usually be replaced by A(I) or A(I)', which can be much faster."
but you can see in the following example that it's 5 times slower!
%----------- example ----------------
a = randi(255,100,100,100);[s1,s2,s3] = size(a);a2 = cell(s3);for k=1:s3 a2{k} = a(:,:,k);end%--------------- (1) faster ------------
ticfor t = 1:1 for i = 1:s1 for j=1:s2 for k=1:s3 b = {a2{k}}; end end endendtoc%---------------- (2) slower -----------
ticfor t = 1:1 for i = 1:s1 for j=1:s2 for k=1:s3 b = a2(k); end end endendtoc%---- Result --------
Elapsed time is 1.188993 seconds.Elapsed time is 5.511241 seconds.
Best Answer