How do I access specific elements from a multi-dimensional array?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Given a milti-dimensional (say 3) array A, I want to access the elements at indices [
], [
] and [
].
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202885/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202886/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202887/image.png)
If I define
and similarly
and
. Then I get A(xi,yi,zi) =
elements. Which is formed all pairs of indices from the array. Thats not what I need. .
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202888/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202889/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202890/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202891/image.png)
How can I get the m pairs - A(xi_i, yi_i, zi_i) ?
0 commentaires
Réponses (1)
Walter Roberson
le 6 Fév 2019
A( sub2ind( size(A), xi, yi, zi ) )
There is a mathematical formula that can be used to convert the indices instead of using sub2ind, but most of the time doing so is less clear.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!