MATLAB: Problem in finding Mean value

Image Processing Toolboxmammogrammean value

Hi,
I want to find mean value of a mammogram only by choosing the values greater than zero. I used for loops with condition but it gives 255 as answer constantly. I don't know what's the mistake i have done.
Code:
[x,y] = size(I);
s = 0;
for i = 1:x
for j = 1:y
if I(i,j) > 0
s = s + I(i,j);
end
end
end
disp('s = ');
disp(s);

Best Answer

Change to
s = s + double(I(i,j));
Question: when you are calculating the mean, are you going to be dividing by the number of values in I, or by the number of non-negative values?
Also are you sure that I will be two-dimensional and not 3 dimensional?
Related Question