Accessing array elements, vector wise

4 ビュー (過去 30 日間)
Bismark Singh
Bismark Singh 2016 年 7 月 14 日
回答済み: Guillaume 2016 年 7 月 14 日
I have an array A whose elements I access in Matlab as A{t}(i,j), where i,t,j are scalars. I instead want to access all the elements at once by having i and j to be vectors of the same length. So I want to do A{t}(i,j) where i,j are vectors of length say n. If I do this, Matlab gives me the result as a matrix of size nxn, since it takes the cartesian product of the inputs. How can I instead get the result a vector of size n: A{t}(first of i, first of j), A{t}(second of i, second of j) etc. without a for loop?

採用された回答

Guillaume
Guillaume 2016 年 7 月 14 日
You need to use sub2ind:
A{t}(sub2ind(size(A{t}), i, j))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by