Code covered by the BSD License  

Highlights from
lexcmp

Be the first to rate this file! 17 Downloads (last 30 days) File Size: 2.57 KB File ID: #23035

lexcmp

by Ben Petschel

 

19 Feb 2009 (Updated 14 Sep 2009)

Fast C-style array/string comparison (by lexical ordering)

| Watch this File

File Information
Description

lexcmp(s1,s2) returns:
 -1, if s1<s2
  0, if s1=s2
  1, if s1>s2
where the comparison is made on the first elements that differ. s1 and s2 can be strings, numeric arrays or other compatible objects (see the help for more details).

Although this has already been done a few times before, this implementation is among the most efficient and the core routine is in a form that easily translates to mex/C (something similar as a built-in function would be nice to have).

The core function is similar to S. Helsen's strcmpc.m with some performance tweaks. The function is vectorized for cell array input. Recent versions allow inf/nan values.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Compare Strings (C-convention)
This submission has inspired the following:
String comparison, multisetdiff, jointable

MATLAB release MATLAB 7.5 (R2007b)
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
14 Sep 2009

added support for inf/nan values in arrays and improved help text

Tag Activity for this File
Tag Applied By Date/Time
string Ben Petschel 19 Feb 2009 16:09:49
compare Ben Petschel 19 Feb 2009 16:09:49
comparison Ben Petschel 19 Feb 2009 16:09:49
string comparison Ben Petschel 19 Feb 2009 16:09:49
lexical Ben Petschel 19 Feb 2009 16:09:49

Contact us at files@mathworks.com