Code covered by the BSD License  

Highlights from
CountMember

5.0

5.0 | 6 ratings Rate this file 31 Downloads (last 30 days) File Size: 1.74 KB File ID: #7738

CountMember

by Jos (10584)

 

27 May 2005 (Updated 21 Dec 2008)

Count members.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

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.
 
Examples:
      countmember([1 2 1 3],[1 2 2 2 2])
         -> 1 4 1 0
      countmember({'a','b','c'},{'a','x','a'})
         -> 2 0 0
 
See also ismember, unique, histc

(v1.2, dec 2008)

MATLAB release MATLAB 6.5 (R13)
Other requirements should work on most ML releases (tested for R13+).
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
31 May 2005 Dimitri Shvorob  
02 Jun 2005 urs (us) schwarz

ery sleek, jos! just a pedestrian thought: replace your dums with the name of the following var, e.g., [AU,dum,j] with [AU,j,j]

08 Feb 2007 Val cucche

:)

05 Dec 2007 Jalal A

many thanks for posting this!

19 Dec 2008 Pete sherer

Excellent. It could be better if you can also return the logical index as a second output.

05 Sep 2011 Abhinav Gaur

just what i needed .. Thanks

Please login to add a comment or rating.
Updates
18 Aug 2005

Reduced overhead by removing unnecessary dummy variables.

18 Aug 2005

Reduced overhead by removing unnecessary dummy variables.

21 Dec 2008

improved help and comments, fixed some spelling issues

Tag Activity for this File
Tag Applied By Date/Time
count member Jos (10584) 22 Oct 2008 07:49:29
cell Jos (10584) 22 Oct 2008 07:49:29
hist Jos (10584) 22 Oct 2008 07:49:29
utilities Jos (10584) 22 Oct 2008 07:49:29
miscellaneous Jos (10584) 22 Oct 2008 07:49:29
unique Jos (10584) 24 Oct 2008 15:38:05
count Jos (10584) 24 Oct 2008 15:38:05
set Jos (10584) 24 Oct 2008 15:38:05
utility Jos (10584) 24 Oct 2008 15:38:05
potw Shari Freedman 20 Apr 2009 13:11:05
pick of the week Jiro Doke 11 Feb 2011 20:12:46

Contact us at files@mathworks.com