Why does ACCUMARRAY used with a custom function sometimes make unnecessary subfunction calls in MATLAB 7.6 (R2008a)?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!