C = COUNTMEMBER(A,B) counts the number of times the elements of array A are present in array B, so that C(k) equals the number of occurences of A(k) in B. A may contain non-unique elements. C will have the same size as A.
A and B should be of the same type, and can be cell array of strings.
I replaced the line:
N = histc(Loc(:), 1:length(AUnique))
N = histcounts(Loc(:), 1:length(AUnique)+1)
based on the recommendation by Mathworks to stop using the histc function. You need to add an extra bin edge because histcounts() doesn't add the extra bin for values exactly equal to the end of the edges vector.