Code covered by the BSD License  

Highlights from
CStrCatStr

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 11.14 KB File ID: #24341
image thumbnail

CStrCatStr

by Jan Simon

 

03 Jun 2009 (Updated 10 Feb 2010)

Cat 2 or 3 strings/cell strings C-MEX: 10 times faster than STRCAT

| Watch this File

File Information
Description

Join 2 or 3 strings and cell strings 10 times faster than STRCAT
 
R = CStrCatStr(A, B) or R = CStrCatStr(A, B, C)
INPUT:
  A, B, C: Strings or cell strings. At least one input must be a cell string.
OUTPUT:
  R: Cell string with the same size as the input cell.

Comparison with Matlab's STRCAT:
- MEX version is about 10 times faster that STRCAT.
- CStrCatStr is limited to 2 or 3 inputs with at least one cell string.
- CStrCatStr conserves marginal spaces.
- STRCAT('A', {}) replies: {'A'}. CStrCatStr('A', {}) replies: {}.
- CStrCatStr treats char arrays as single string with linear index.

EXAMPLES:
  CStrCatStr('a', {'a', 'b', 'c'}) % ==> {'aa', 'ab', 'ac'}
  CStrCatStr({'a'; 'b'; 'c'}, '-') % ==> {'a-'; 'b-'; 'c-'}
  CStrCatStr({' ', ''}, 'a', {' ', ''}) % ==> {' a ', 'a'}
  CStrCatStr({'a', 'b'}, {'c'}) % ==> error: cells need equal size
  FileDir = dir(Path); AbsName = CStrCatStr(Path, filesep, {FileDir.name});

Tested: Matlab 6.5, 7.7, 7.8, Win2K/XP, LCC2.4, LCC3.8, BCC5.5, 32 + 64 bit addressing.
Run unit-test TestCStrCatStr after compiling and for a speed test (see screen shot).
Compiled Mex: http://www.n-simon.de/mex

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Works under Matlab 6.5 also
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
24 Jun 2009

Shorter description, sources are not changed

10 Feb 2010

32 + 64 bit addressing

Tag Activity for this File
Tag Applied By Date/Time
strcat Jan Simon 04 Jun 2009 09:16:15
concatenation Jan Simon 04 Jun 2009 09:16:15
string Jan Simon 04 Jun 2009 09:16:15
cell string Jan Simon 04 Jun 2009 09:16:15
mex Jan Simon 25 Jun 2009 09:31:49
cat Jan Simon 11 Feb 2010 10:02:25

Contact us at files@mathworks.com