why when i use find command to find the index i face problem

1 回表示 (過去 30 日間)
mehmet salihi
mehmet salihi 2021 年 5 月 18 日
回答済み: Mathieu NOE 2021 年 5 月 18 日
please it is urgent for me, why when i try to find the index of 0.3 it gives me the double information rather than showing the index 3 like others.

回答 (2 件)

Daniel Pollard
Daniel Pollard 2021 年 5 月 18 日
I had a play with my version of Matlab and found the same result. I think what you've stumbled on is a floating point error. There is a workaround:
t = 0:0.1:1.8;
find(round(t, 10) == 0.3)
ans = 4
This rounds all the elements of t to 10 significant figures before performing find.

Mathieu NOE
Mathieu NOE 2021 年 5 月 18 日
hello
no , matlab tells you that it could NOT find an exact match to value = 0.3 (there must be a very tiny numerical difference , so use method with a tolerance (to be defined) :
ind = find(abs(t - 0.3)<tol)

カテゴリ

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