フィルターのクリア

How do I solve the following problem with rounding?

2 ビュー (過去 30 日間)
Nikola Mirkov
Nikola Mirkov 2014 年 10 月 21 日
編集済み: Jan 2014 年 10 月 21 日
I run the following code:
clear all
x=-2:0.1:2;
find(x==0.9)
I get:
ans = Empty matrix: 1-by-0
How can I fix this problem? The version I use is R2013a.
Thanks! niko
  1 件のコメント
Jan
Jan 2014 年 10 月 21 日
編集済み: Jan 2014 年 10 月 21 日
Avoid the clear all, because this is more brute than useful.
This is one of the most frequently asked questions. I suggest to read the other ones also: http://matlab.wikia.com/wiki/FAQ

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

回答 (2 件)

Amir
Amir 2014 年 10 月 21 日
編集済み: Amir 2014 年 10 月 21 日
Please try this:
x=-2:0.1:2;
find(abs(x-0.9) < eps)
ans =
30

Pierre Benoit
Pierre Benoit 2014 年 10 月 21 日
You can use a tolerance :
find(abs(x-0.9) < tol)

カテゴリ

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