Code covered by the BSD License  

Highlights from
CountMember

5.0

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

CountMember

by

 

27 May 2005 (Updated )

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   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
05 Sep 2011 Abhinav Gaur

just what i needed .. Thanks

19 Dec 2008 Pete sherer

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

05 Dec 2007 Jalal A

many thanks for posting this!

08 Feb 2007 Val cucche

:)

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]

31 May 2005 Dimitri Shvorob  
Updates
18 Aug 2005

Reduced overhead by removing unnecessary dummy variables.

21 Dec 2008

improved help and comments, fixed some spelling issues

Contact us