フィルターのクリア

From a given number how to find the value closest to zero in a vector.

38 ビュー (過去 30 日間)
Alexandros Samp
Alexandros Samp 2016 年 9 月 27 日
回答済み: Kelly Kearney 2016 年 9 月 27 日
If a have a vector [93.60 119.15 136.19 191.55 238.39 268.20 302.27 340.60 383.18 425.77] and a number that every time is different.For example numb=410 i want to find the number 383.18 from the vector.

採用された回答

Star Strider
Star Strider 2016 年 9 月 27 日
Use the find function:
vector = [93.60 119.15 136.19 191.55 238.39 268.20 302.27 340.60 383.18 425.77];
numb=410;
idx = find(vector <= numb, 1, 'last');
Result = vector(idx)
Result =
383.18

その他の回答 (1 件)

Kelly Kearney
Kelly Kearney 2016 年 9 月 27 日
Star's answer works in the values in the vector are sorted. If not, min might be a better choice:
vector = [93.60 119.15 136.19 191.55 238.39 268.20 302.27 340.60 383.18 425.77];
numb=410;
[~, imin] = min(abs(vector - num));
vector(imin)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by