Arg max without using a loop
이전 댓글 표시
I am looking for a method to reproduce the following without using a loop.
The issues come from the fact that the matrices I am using are too big and I could save some space avoiding to create a third matrix C to do the job.
My aim is to find some function f that does something similar to B = f(B(policy)). Is it possible to do it?
A = rand(10,20,30);
B = rand(10,20,30);
[A_hat, policy] = max(A,[],3);
for i = 1:10
for ii = 1:20
C = B(i,ii,policy(i,ii));
end
end
Thanks for the attention.
Sincerely
Luca
채택된 답변
추가 답변 (1개)
Luca Gagliardone
2017년 8월 8일
0 개 추천
댓글 수: 2
Adam
2017년 8월 8일
Well, everything is linear indexing under the hood anyway.
Luca Gagliardone
2017년 8월 9일
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!