I have an integer array of length 2000 elements. For ex
x = [2, 4, 5, 6, 5,6,7,5......];
Now in this array i need to find an element which occurs repeatedly. For ex I need to know how many times a number ‘5’ has been occurred. In the above example it is three times.
Is there any way to search an matching element and returns the count in matlab?
Do you know the number in advance?
If so, to work out how many times it appears in
xyou could do:The
x==5creates a vector of[FALSE FALSE TRUE FALSE TRUE FALSE FALSE TRUE ...], beingTRUEwheneverxis 5.The
sumthen adds up that vector, whereFALSEmaps to 0 andTRUEto 1.