access the element of multidimensional array given the subscript array

1 回表示 (過去 30 日間)
zhang
zhang 2014 年 2 月 20 日
回答済み: Azzi Abdelmalek 2014 年 2 月 20 日
Given a multidimensional array A = MxMxMx...xM, where ndims(A)=n and the subscript array b=[a1, a2, ..., an]. How to get A(a1, a2, a3, ..., an)? I've tried A(b). It's not a correct way. And a correct way is to write a function to convert the subscript array to the index, saying i, and then we can use A(i) to get what I want. Is there an easier way?
Thanks

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 20 日
lin_ind=sub2ind(size(A),a1,a2,a3)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by