View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.89 KB File ID: #16894 Version: 1.0



Ben Barrowes (view profile)


15 Oct 2007 (Updated )

Applied relational operators to such as == or < to character arrays or cell arrays of strings accord

| Watch this File

File Information

% function out=strrel(in1,in2,relop)
% Compares strings according to strcmp and issorted according to relop
% in1 and in2 can be character arrays or cell arrays
% relop can be <, <=, >, >=, ==, and ~=, or their string equivalents
% such as 'ne' or 'gt', etc.
% Examples:
% c = {'How','much','wood','would','a','woodchuck','chuck?'};
% s = 'wood';
% r = strrel(s,c,'<')
% r = strrel(s,c,'gt')

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
13 Jun 2012 Ahmed Fasih

issortedcellchar not found in 2012a.

Comment only
17 Oct 2007 Urs (us) Schwarz

since you seem to listen to your customers, i now show you the fastest solution, which will drop the execution time to ~25% of your current version:

% the crucial part of the engine
ie =strcmp(in1,in2);
for i=1:numel(in1)
is=issortedcellchar({in1{i},in2{i}}); %!!!
switch lower(relop)
case {'<','lt'}
out(i)=is & ~ie(i);
case {'<=','le'}
out(i)=is | ie(i);
case {'==','eq'}
case {'~=','ne','!=','/='}
case {'>','gt'}
out(i)=~is & ~ie(i);
case {'>=','ge'}
out(i)=~is | ie(i);
error([relop,' is not recognized'])

also, being an academic yourself, you certainly know how to acknowledge the contributions of others to your work, which may not simply be a SMALL BUGFIX as mentioned earlier...


16 Oct 2007 urs (us) schwarz

nice idea... a few remarks
1) the help section needs a bit of work, eg, H1 and syntax
2) the last switch statement should read GE instead of GT
3) the engine could be vectorized, eg
t={the token};
c=the cellstring;
is=cellfun(@(x) issorted([t,{x}]),c);
% the swith, eg, 'gt'
out=~is & ~ie

just some thoughts

Comment only
17 Oct 2007

Small bugfix.

Contact us