# Array divided by 255 gives me 0

8 views (last 30 days)
Thomas Koelen on 7 Apr 2015
Commented: James Tursa on 7 Apr 2015
I have an matrix that looks like this (but bigger)
[30 29 31;
29 30 30;
30 31 30]
now when I divide it by 255, it gives me this:
[0 0 0;
0 0 0;
0 0 0]
As far as I know I never changed anything with digits, does anyone have an idea what's going on?
Kind regards
edit: the matrix contains doubles

Joep on 7 Apr 2015
Edited: Joep on 7 Apr 2015
This is because you matrix was written in uint8. You should first convert it to double.
double([30 29 31; 29 30 30; 30 31 30])
It's not clear why it is in uint8 maybe you load some image or create uint8 matrix.
PS: uint8 means you got a 8 bit number so 2^8=256 which will give 0->255. If you need some help I can help you also in dutch.
##### 2 CommentsShowHide 1 older comment
James Tursa on 7 Apr 2015
Most likely you thought you had converted it to double, but hadn't. Then you restarted MATLAB and wiped out the evidence.

Ilham Hardy on 7 Apr 2015
testmat = [30 29 31; 29 30 30; 30 31 30] ;
testmat =
30 29 31
29 30 30
30 31 30
>> testmatdev = testmat./255
testmatdev =
0.1176 0.1137 0.1216
0.1137 0.1176 0.1176
0.1176 0.1216 0.1176
Thomas Koelen on 7 Apr 2015
It's not working either, ran my code on another pc and it's working just fine. After reopening Matlab on my own computer it's also running fine.
Thanks though!

### Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!