フィルターのクリア

how to let my code just consider the demical number ??

1 回表示 (過去 30 日間)
Muhammad RSMY
Muhammad RSMY 2017 年 12 月 27 日
コメント済み: Muhammad RSMY 2017 年 12 月 27 日
Dear friends
sorry for bothering you guy, can anyone help how to code, asking matlab to only consider the decimal
for example 45.789
I just be coding need to detect the numbers after (.), in another words I need to detect only 789
maybe my question is so silly but sorry due to lack of my knowledge
Thanks a lot guys
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 27 日
Is the input a string? Because if it is floating point then there are multiple valid answers. Remember that floating point numbers are not stored in decimal and that 1/10 cannot be exactly represented in floating point, much the same way that 1/3 cannot be exactly represented in finite decimal

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

採用された回答

David Goodmanson
David Goodmanson 2017 年 12 月 27 日
編集済み: David Goodmanson 2017 年 12 月 27 日
Hi Muhammad,
You need the integer part, and the fix function works:
a = 45.789
>> fix(a)
ans = 45
>> b = a-fix(a)
b = 0.7890
For positive a, the floor function gives the same result as fix. However, fix works for both positive and negative a (giving -.789 in the latter case). Floor works as intended only for positive a. See help floor, help fix for the difference in the two functions.
Another way, which also works for both signs, is
b = rem(a,1)
  2 件のコメント
Image Analyst
Image Analyst 2017 年 12 月 27 日
What does that mean? There are many, many digits to the right of the decimal place. What does "consider" mean to you? Do you want to multiply by 1000 and cast to integer so you get only 3 decimal places? If not, then what you do mean exactly?
Muhammad RSMY
Muhammad RSMY 2017 年 12 月 27 日
Thanks problem is solved

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

その他の回答 (1 件)

Muhammad RSMY
Muhammad RSMY 2017 年 12 月 27 日
Thanks David Goodmanson and Image Analyst for your kind support and suggestions
appreciated

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by