How to create a program that compares outputs in dictionary lexicographic

조회 수: 2 (최근 30일)
Ryan Peters
Ryan Peters 2018년 4월 4일
답변: CARLOS RIASCOS 2018년 4월 4일
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