No BSD License  

Highlights from
String comparison

5.0

5.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.63 KB File ID: #23375

String comparison

by ChinSoon Lim

 

19 Mar 2009

Compares 2 strings. Output is identical to that of C string library.

| Watch this File

File Information
Description

Compares 2 strings, str1 and str2 and return -1 if str1 < str2, 0 if str1==str2 and 1 if str1 > str2. output is identical to that of C string library.

Same idea as files listed in acknowledgments. The difference is that this implementation is faster since it uses mex function.

Type mex strcmpC.c at the MATLAB prompt to generate the mex file. Then call strcmpC like any MATLAB function.

Example usage:
strcmpC('1234','2345535')
ans =
    -1

Source code heavily references a mex example. See mxmalloc.c.
Type the following command in MATLAB prompt to see mxmalloc.c
edit([matlabroot '/extern/examples/mx/mxmalloc.c']);

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Compare Strings (C-convention), C-Style String Comparisons, lexcmp

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
02 Oct 2010 Zhiqiang Zhang  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
string comparison ChinSoon Lim 20 Mar 2009 13:40:10

Contact us at files@mathworks.com