Code covered by the BSD License  

Highlights from
CStrAinBP

5.0

5.0 | 2 ratings Rate this file 2 Downloads (last 30 days) File Size: 37.26 KB File ID: #24380
image thumbnail

CStrAinBP

by Jan Simon

 

09 Jun 2009 (Updated 12 Sep 2009)

Overlapping elements of 2 cell strings. 10-20 times faster than INTERSECT/ISMEMBER/SETDIFF.

| Watch this File

File Information
Description

Find overlap of 2 cell strings.
This can be used for a faster calculation of:
  INTERSECT, ISMEMBER, SETDIFF and UNION.

Comparison to Matlab's INTERSECT:
- Consider repeated strings (no internal UNIQUE)
- No sorting
- Can be insensitive for upper/lower case
- M-version as demonstration of the method
- MEX-version: 90% to 98% faster than INTERSECT

[AI, BI] = CStrAinBP(A, B, CaseSensitive)
INPUT:
  A, B: Cell strings.
  CaseSensitive: Optional string to trigger sensitivity for case.
OUTPUT:
  AI: Indices of common strings in A.
        Each occurence of repeated strings is considered.
        AI is sorted from low to high indices.
  BI: Indices of common strings in B.
        If B is not unique, the first occurrence of a string is used.
  such that A{AI} == B{BI}.

EXAMPLES:
  [AI, BI] = CStrAinBP({'a', 'b', 'q', 'a'}, {'a', 'c', 'd', 'a', 'b'})
  replies: AI = [1, 2, 4] and: BI = [1, 5, 1]

  [AI, BI] = CStrAinBP({'a', 'b', 'A'}, {'a', 'c', 'a', 'B', 'b'}, 'i')
  replies: AI = [1, 2, 3] and: BI = [1, 4, 1]

INCLUDED FILES:
  CStrAinBP.m: Proof of concept, demonstration.
  CStrAinBP.C: Fast MEX function.
  CStrAinBP.MEXW32: Compiled for Matlab 7 with LCC3.8.
                    Please recompile it with your favorite compiler.
  Matlab6/CStrAinBP.DLL: Compiled for Matlab 6 with BCC5.5.
                    For Matlab 6, replace the MEXW32 file by this DLL.
  TestCStrAinBP: Run the test after installation or compiling.

Tested: Matlab 6.5, 7.7, 7.8, Win2K/XP

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Works under Matlab 6.5.1 also.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
01 Jan 2010 Michael

Works well- thanks!

22 Sep 2010 Brahim HAMADICHAREF

Excellent contribution, saving me a lot of time !

Please login to add a comment or rating.
Updates
12 Sep 2009

- Sensitivity for case triggered by 3rd input.
- Don't crash for uninitialized cell elements.
- Cleaned doc.

Tag Activity for this File
Tag Applied By Date/Time
string Jan Simon 09 Jun 2009 11:15:31
cell string Jan Simon 09 Jun 2009 11:15:31
comparison Jan Simon 09 Jun 2009 11:15:31
ismember Jan Simon 09 Jun 2009 11:15:31
mex Jan Simon 09 Jun 2009 11:15:31
intersect Jan Simon 09 Jun 2009 11:15:31
setdiff Jan Simon 14 Sep 2009 09:55:05
lookup Jan Simon 18 Sep 2009 04:03:16

Contact us at files@mathworks.com