How to represent decimal number

a=180/255; in a matlab program and type 'a' in Command window, it shows the result as '0.7058823529411765' but when b=180; c=255; a=b/c; (which is doing the same function as above) and type 'a' in Command window, it shows the result as '1'

2 件のコメント

James Tursa
James Tursa 2016 年 9 月 10 日
I don't think you are giving us the complete picture. E.g., on my computer:
>> b=180; c=255; a=b/c;
>> a
a =
0.705882352941177
Please start over with a clean workspace, then type in the above and see what happens. I think you will get the expected results.
If you can reproduce your '1' with other code, please show us that code.
Arun Prem
Arun Prem 2016 年 9 月 10 日
編集済み: Stephen23 2016 年 9 月 10 日
Thanks for your response. My requirement is, in a Matlab program I have to find the maximum & minimum pixel value in an image and divide it by 255. So I have found the maximum & minimum pixel value using the command in a program. Below lines in a Matlab program.
New=imread('11.jpg');
Dif=rgb2gray(New);
[b,idx]=max(Dif(:));
[c,idx]=min(Dif(:));
a1=b/255;
a2=c/255;
After running the program, When I go to Command prompt and type,
b =175
c =114
a1 =1
a2 =0
But actually a1 and a2 values should be different....

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

回答 (1 件)

Steven Lord
Steven Lord 2016 年 9 月 10 日

0 投票

One or both of the variables b and c are of type uint8. See this documentation page for information about how integer arithmetic is performed.

カテゴリ

ヘルプ センター および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

質問済み:

2016 年 9 月 10 日

編集済み:

2016 年 9 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by