Here is a 10x10 array arr.
This arr has 100 elements. And it has distribution from -10 to 10 and there are 5 0-value.
I did this code because I wanted to know the number of 0.
count = 0;
for i = 1: 10
for j = 1: 10
if (arr (i, j) == 0)
count = count +1;
end
end
end
Logically, count should be 5 in MATLAB's workspace. and i and j are 10.
However, when I run the code, count is 0.
This code can not count the numbers.
How can I count the numbers?
countis zero, your array doesn’t have any zero values in it, because your code is correct. Wolfie explained in his answer how to count “almost zeros”, which seems to have been useful to you. But I wanted to add that your code is correct to count the number of values identical to 0.