How to create a program that compares outputs in dictionary lexicographic

2 次查看(过去 30 天)
a function B=compare(s,t) that outputs "1" if s<=t in dictionary lexicographic ordering, and "0" if s>t in dictionary lexicographic ordering so that you can use it in IF statements.

回答(1 个)

CARLOS RIASCOS
CARLOS RIASCOS 2018-4-4
Hi, try this function, it worked for me !, look how I use it in the image:
function tlex = compare(int1,int2)
Lex = ['a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q'...
'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z'];
Lex_value=1:length(Lex);
a=find(Lex == int1);
b=find(Lex == int2);
if Lex_value(a) > Lex_value(b)
tlex=0;
elseif Lex_value(a)<= Lex_value(b)
tlex=1;
end
end

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by