String comparison

version (1.63 KB) by ChinSoon Lim
Compares 2 strings. Output is identical to that of C string library.


Updated 10 Apr 2016

View License

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:
ans =
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']);

Cite As

ChinSoon Lim (2022). String comparison (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!