How idx runs and give its value ?

24 ビュー (過去 30 日間)
Atique Barudgar
Atique Barudgar 2019 年 11 月 8 日
回答済み: M 2019 年 11 月 8 日
a=[34.8 31 29 26.7 39.5]; %dummy data
n=33;
[val,idx]=min(abs(a-n));
minVal=a(idx)
After running:
Now I am not clear when in answer idx=1
then how a(idx)=34.8 came
Even I am not clear about idx...why its values change everytime

回答 (1 件)

M
M 2019 年 11 月 8 日
abs(a-n) =
1.8000 2.0000 4.0000 6.3000 6.5000
then min(abs(a-n)) = 1.8, and the location of this minimum value (idx) appears at the first value of the vector.
Where is the problem ?

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by