5.0

5.0 | 5 ratings Rate this file 115 downloads (last 30 days) File Size: 1.74 KB File ID: #7738

CountMember

by Jos

 

27 May 2005 (Updated 21 Dec 2008)

Code covered by BSD License  

Count members.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | 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 (5)
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.

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 22 Oct 2008 07:49:29
cell Jos 22 Oct 2008 07:49:29
hist Jos 22 Oct 2008 07:49:29
utilities Jos 22 Oct 2008 07:49:29
miscellaneous Jos 22 Oct 2008 07:49:29
unique Jos 24 Oct 2008 15:38:05
count Jos 24 Oct 2008 15:38:05
set Jos 24 Oct 2008 15:38:05
utility Jos 24 Oct 2008 15:38:05
potw Shari Freedman 20 Apr 2009 13:11:05
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com