I have a matrix X(1e4,20) which takes on values 0:4.
I’m interested in finding (row by row) the number of times values are ~=0, ==1&2&3 and ==3
Why doesn’t
eg:
X=randi([0 4],1e4,20)
for ii=1:1e4
onestwosorfours(ii,1)=sum(X(ii,:)==1|2|4)
end
work?
I’ve ended up doing
sum(X(ii,:)==1)+sum(X(ii,:)==2), etc
This expression is wrong:
You are finding the bitwise or of
1,2and4which istrue, because anything other thanfalseor0istrue. Then you are finding the amount of times that the array equals the number.Instead, rewrite it as :
Or, even better
Which clarifies what you really meant.