How can I count the number of zero elements in a vector using MATLAB?

1 reply · 5K views · last reply
Fert
Messages
6
Reaction score
0
I'm trying to write an m-file in MATLAB that can count how many data point in a vector are zero, how many are 1, etc. I can call the vector and get the length, max and min values, but I also need to be able to call each element seperatly and I can't figure out how to do this. I've been playing around and this is what i have:

function len (A)
N= length(A);
M =max(A);
m=min(A);
S=0;
for i=1:N

if
A[i,1]=0;
S=S+1;
end



len=N
MAX =M
MIN=m
zero=S

But it says expression (A=[i,1]=0) is incomplete. I've tried a few other expressions but none work. Any help is appreciated.
 
When you reference an element in Matlab, you use parenthesis, if I remember correctly. So you'd need to reference A(i,1).