How can I use the function FIND to count the number of items of a given value instead of using a loop? For example, in the array item below there are 3 occurrences of the number 23, 2 occurrences of the number 22, and 2 occurrences of the number 20.
....
for i=2:n
if item(i-1)~=item(i)
nItem21(i)=1;
else
nItem21(i)=nItem21(i-1)+1;
end
end
item Num
23 2
23 4
23 6
22 3
22 1
20 6
20 8
You can do the following: identify where the value of
itemchanges, then use diff to get the counts.