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?

Plus de réponses (0)

Catégories

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by