They've been making lots of changes to the histogram routines over the last couple of versions, which makes it harder/longer for us to give answers to questions like yours. Assuming you have a recent version, you can use histcounts() and sum the bins that have counts of 2 or more:
n = 7
r = randi(100,n,1)
% Test case
r = [30 17 94 28 28 19 19]
[counts, edges] = histcounts(r, min(r):max(r)) % a new function!
binsOfDuplicates = counts >= 2
numDuplicates = sum(counts(binsOfDuplicates))
If you have an old version, you can use histc(), which has now been deprecated:
n = 7
r = randi(100,n,1)
% Test case
r = [30 17 94 28 28 19 19]
counts = histc(r, min(r):max(r))
binsOfDuplicates = counts >= 2
numDuplicates = sum(counts(binsOfDuplicates))