from
wordcomp.m
by Aman Siddiqi
Alphabatizes words & returns lowest(first in list)
|
| answer=wordcomp(word1,word2)
|
function answer=wordcomp(word1,word2)
% Enter words as strings word2num('word','word')
% returns the lower word alphabeticaly
% wordcomp('def','abc','zz') yields 'abc'
% wordcomp('test','m') yields 'm'
% wordcomp('test','te') yields 'te'
% normalizes words to same length
if length(word1)>length(word2);
smaller=length(word2);
letters=length(word1);
word2(1,smaller+1:letters)=0;
else
smaller=length(word1);
letters=length(word2);
word1(1,smaller+1:letters)=0;
end;
% compares words letter by letter
indx=1;
while indx<letters+1
if word1(indx)<word2(indx)
answer=word1;
indx=letters+1; % stops comparison
elseif word1(indx)==word2(indx)
indx=indx+1;
answer=word1; % this is here in case the two words are the same
else
answer=word2;
indx=letters+1; % stops comparison
end
end
|
|
Contact us at files@mathworks.com