MATLAB: Why matlab rounding the result itself

image processingmatrix

my code is given below-
w=imread('win.png');%its a 32X32 picture
for i=1:32
for j=1:32
wrr(i,j)=w(i,j)*.02;
end
end
disp('wrr');
disp(wrr);
the problem is- its rounding the pixel values,like if w(i,j)=178 then after multiplication with .02 wrr(i,j)=4 where it should be 3.56. i need the floating point for further work. can anyone help?

Best Answer

You need to cast ‘w’ as double before you do the calculations. You can recast it as whatever it was previously to save it later.
The easiest way might be:
w=imread('win.png');%its a 32X32 picture

wrr = double(w);
for i=1:32
for j=1:32
wrr(i,j)=wrr(i,j)*.02;
end
end
disp('wrr');
disp(wrr);
That preserves the original ‘w’ if you want to do that.
However the easiest way to do what you want is simply:
w=imread('win.png');%its a 32X32 picture
wrr = double(w) * 0.02;