フィルターのクリア

Logical indexing in maltab

1 回表示 (過去 30 日間)
Bharat
Bharat 2015 年 6 月 17 日
コメント済み: James Tursa 2015 年 6 月 17 日
Hello,
I need help regarding a code.:
Sal = para(i,7); y= X(X<Sal); this doesn't change the output
The vaulue of Sal is = 0.005. If I use this, then it returns the right value.
y = X(X<0.005); this returns the correct output.
How do I resolve this issue.
Thanks.
  1 件のコメント
Stephen23
Stephen23 2015 年 6 月 17 日
編集済み: Stephen23 2015 年 6 月 17 日
Learn about binary floating point numbers, and how they cannot accurately represent all decimal fractions:
You might also like to try using this, to find out what the value really is:

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

回答 (2 件)

James Tursa
James Tursa 2015 年 6 月 17 日
If I understand your question, you are saying that y= X(X<Sal) returns a different result than y = X(X<0.005), even though Sal = 0.005.
I would hazard a guess that Sal is not really 0.005, but is a number close to 0.005 that displays the same as 0.005. What do you get with the following:
Sal == 0.005
  3 件のコメント
Bharat
Bharat 2015 年 6 月 17 日
I just checked. y=X(X<0.005010368459505) also doens't work. however y=X(X<0.005) works, which suggests that it related to number of significant digits. How do I change the number of significant digits?
Thanks
James Tursa
James Tursa 2015 年 6 月 17 日
I think you now need to give us a more complete picture of what you are doing and what "doesn't work" means. If y=X(X<0.005) "works", then why aren't you doing that explicitly? Is the real problem that you need to round Sal to the nearest 3-decimal place number for some reason? Or what?

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


Walter Roberson
Walter Roberson 2015 年 6 月 17 日

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by