Why does ACCUMARRAY used with a custom function sometimes make unnecessary subfunction calls in MATLAB 7.6 (R2008a)?
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!