report a MATLAB problem (calling cell as {A{i}} being faster than A(I))
Afficher commentaires plus anciens
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 ------------
tic
for t = 1:1
for i = 1:s1
for j=1:s2
for k=1:s3
b = {a2{k}};
end
end
end
end
toc
%---------------- (2) slower -----------
tic
for t = 1:1
for i = 1:s1
for j=1:s2
for k=1:s3
b = a2(k);
end
end
end
end
toc
%---- Result --------
Elapsed time is 1.188993 seconds.
Elapsed time is 5.511241 seconds.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Elementary Math dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!