How to find elements equal to specific values?

4 ビュー (過去 30 日間)
andrea
andrea 2014 年 10 月 14 日
コメント済み: andrea 2014 年 10 月 14 日
This is my vector (double): v=[0.5;0.6;0.7;0.8;0.9;1.0];
I would like to find the position of 0.95 or of the nearest element to 0.95
This is what I do: pos=find(abs(inorm-0.95) < eps); %clearly it doesn't work becouse v==0.95 doesn't exist
Thanks in advance for your help!

採用された回答

Adam
Adam 2014 年 10 月 14 日
編集済み: Adam 2014 年 10 月 14 日
[m, i] = min( abs( v - 0.95 ) )
m there is the distance of the nearest value in the vector from 0.95 and i is its index.
This will find the first of any any elements equidistant from 0.95 so if you want to find all of them or the last or something different then it will need to be a little more complicated.
  1 件のコメント
andrea
andrea 2014 年 10 月 14 日
Thanks...!:)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by