フィルターのクリア

How to find elements of an array by using another array elements as indices

3 ビュー (過去 30 日間)
Cenk  Bursali
Cenk Bursali 2020 年 5 月 17 日
コメント済み: Cenk Bursali 2020 年 5 月 18 日
Hi everyone,
Let's say
A= [2 5 4 3 5 7 5 6 8 2 8 4 3 1 4];
B= [1 3 4 7];
I need to find elements of A by using elements of B as indices of elements of A. In other words, I need 1st, 3rd, 4th and 7th elements of A and information of indices is given in B. Is this possible without using for loop? If yes, how? I am glad if you can help.
  2 件のコメント
Stanislao Pinzón
Stanislao Pinzón 2020 年 5 月 17 日
You can use
A(B)
madhan ravi
madhan ravi 2020 年 5 月 17 日
Stanislao I suggest you to move it as an answer since it answers the question.

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

採用された回答

Ang Feng
Ang Feng 2020 年 5 月 17 日
Matlab allows you to acces elements of a matrix in serveral ways. In your case, try this
A(B)
I have this results from Matalab
A(B)
ans =
2 4 3 5
, which is what you are looking for.
Other ways of indexing a matrix can be found here

その他の回答 (0 件)

カテゴリ

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