How do I access specific elements from a multi-dimensional array?

조회 수: 1 (최근 30일)
Aditya Nanda
Aditya Nanda 2019년 2월 5일
답변: Walter Roberson 2019년 2월 6일
Given a milti-dimensional (say 3) array A, I want to access the elements at indices [ ], [] and [ ].
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. .
How can I get the m pairs - A(xi_i, yi_i, zi_i) ?

답변 (1개)

Walter Roberson
Walter Roberson 2019년 2월 6일
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.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by