MATLAB: Function similar to count

countcounting occurence of a valueinbuilt function

Is there any function similar to count that can be used in an array of 1's,-1's and 0's to count the number of 1's present in a particular range?

Best Answer

One approach:
A=randi([-1 1],1,100);%random data for -1,0 and 1
cnt=sum(ismember(A,1));%counts the number of 1 in array A