フィルターのクリア

How do you return the value of one vector at specified value of another vector

2 ビュー (過去 30 日間)
balsip
balsip 2017 年 1 月 26 日
編集済み: Guillaume 2017 年 1 月 26 日
I want to return the value of a vector A at the specified value of vector B.
So, when vector B = 805, I'd like code to return the value of vector A.
They're the same length.

採用された回答

Matt J
Matt J 2017 年 1 月 26 日
編集済み: Matt J 2017 年 1 月 26 日
It's not entirely clear what you mean. Possibly, you want this
A(B==805)
or you could mean,
A(B)
  3 件のコメント
Matt J
Matt J 2017 年 1 月 26 日
編集済み: Matt J 2017 年 1 月 26 日
Then the first answer should have worked. Clearly, your B vector does not contain any occurrence B(i)==805, or at least not exactly. You may need a floating point tolerance.
Guillaume
Guillaume 2017 年 1 月 26 日
編集済み: Guillaume 2017 年 1 月 26 日
A(ismembertol(B, 805))
may fix the problem with the value in B not being exactly equal to 805 (due to floating point calculations)
Or if all the values in B are supposed to be integer:
A(round(B) == 805)

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2017 年 1 月 26 日
Why have you not tried the obvious? What does
A(B)
provide?
It appears that you need to spend time reading the getting started tutorials for MATLAB if you do not understand how to use an index.

カテゴリ

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