フィルターのクリア

Mod function returns decimal value?

24 ビュー (過去 30 日間)
SNEHA P S
SNEHA P S 2017 年 7 月 20 日
回答済み: Jan 2017 年 7 月 20 日
I was trying to generate some random sequence using chaotic tent map. After generating some values i would like to convert them to a higher value which helps to perform some operation with pixel values of an image. So i used an equation "s = mod((y * (10^10)),256);" where y is the generated sequence using tent map. But after performing this mod operation the result i got was weird because it outputs decimal values like 0, 240.959269494109, 225.918538988219, 210.877808482386, 195.837077976437. Why this happens? The output of mod operation should be an integer, right?? Instead of Modulo i tried rem() function also. The result was same. Please help me.

採用された回答

Jan
Jan 2017 年 7 月 20 日
The output of mod operation should be an integer, right??
No.
The output of modulo operation returns the remainder value, right?
Yes.
The remainder is the rest after the division. 9.83 divided by 3 = 3*3 + 0.83, such that 0.83 is the remainder - and this need not be an integer.

その他の回答 (1 件)

David Goodmanson
David Goodmanson 2017 年 7 月 20 日
Hi sneha,
You have already demonstrated that mod does not necessarily output integers. Something like
s = mod(round(y*10^10),256)
would.
  3 件のコメント
Stephen23
Stephen23 2017 年 7 月 20 日
編集済み: Stephen23 2017 年 7 月 20 日
"But the output of modulo operation returns the remainder value, right? So i think it must be an Integer."
Why must the remainder be an integer? Whoever taught you that should be fired from their teaching job.
>> mod(5,1.5)
ans = 0.50000
>> mod(5.3,2)
ans = 1.3000
You should be looking at y and the input values that you are providing.
David Goodmanson
David Goodmanson 2017 年 7 月 20 日
編集済み: David Goodmanson 2017 年 7 月 20 日
Suppose both numbers here are positive for simplicity. By definition the remainder is the positive quantity that is left over after you evenly divide the first number by the second as many times as possible.
6.7 = 3*2 + .7
>> mod(6.7,2)
ans = 0.7000
Naturally if both numbers are integers the remainder will be an integer. But that's not what you had, and that's why I suggested using the round command.

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

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by