How can I select a three dimensional diagonal from a three dimensional array?
이전 댓글 표시
I have a scalar s.
I have a 3D array M(nx,nr,N), where in this case nx=100, nr=10, and N=30.
Dimension 1 takes index values from a vector X which has nx possible elements. Similarly for the r dimension. The N dimension is just a count n=1:N.
I have N observations of a variable, each with an index point (ix,ir,n). I can collect the indices for all N observations in three index vectors.
I then perform the following operation: Z=s<=M(IX,IX,:);
But all i really want as an outcome is the "diagonal" which picks the N points I am looking for.
M(IX(1),IR(1),1)
M(IX(2),IR(2),2)
etc
M(IX(N),IR(N),N)
How can I do this in one command?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!