How do I access specific elements from a multi-dimensional array?
显示 更早的评论
Given a milti-dimensional (say 3) array A, I want to access the elements at indices [
], [
] and [
].
], [
] 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. .
and similarly How can I get the m pairs - A(xi_i, yi_i, zi_i) ?
回答(1 个)
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!