Why does ACCUMARRAY used with a custom function sometimes make unnecessary subfunction calls in MATLAB 7.6 (R2008a)?
Afficher commentaires plus anciens
I have the defined the following function:
function A = testfun()
val = 101:105;
subs = [1 2 2 2 2;
1 1 3 1 3]';
A = accumarray(subs, val,[2 3], @(x) myfun(x));
function k = myfun(x)
disp(['new call to myfun with x = ' num2str(x')])
k={x};
end
end
When I run the above function, though I get the expected final result, A, it appears that more calls are made to the subfunction 'myfun' than are necessary:
new call to myfun with x = 101
new call to myfun with x = 102
new call to myfun with x = 101
new call to myfun with x = 104 102
new call to myfun with x = 105 103
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!