Accessing to the position stored in a variable

1 回表示 (過去 30 日間)
Mohsen  Davarynejad
Mohsen Davarynejad 2011 年 12 月 10 日
Suppose I have a matrix, A=rand(5,5) and an array, b=[2,3]. How can I extract the A(2,3) element? I know a simple solution is A(b(1), b(2)), but the problem is that I may end up with a high dimensional A matrix and I do not want to write something like: A(b(1), b(2), b(3),…., b(n)).

採用された回答

Walter Roberson
Walter Roberson 2011 年 12 月 10 日
The below does not look like much, but it uses a powerful MATLAB facility:
t = num2cell(b);
A(t{:})
  1 件のコメント
Mohsen  Davarynejad
Mohsen Davarynejad 2011 年 12 月 10 日
Many thanks Walter, It's perfectly matches what I was looking for.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by