Question
(P2) (P9.2.5) In MATLAB, without using sort, implement the following function so that it performs as specfied: function a = compare1 ( s1 , s
(P2) (P9.2.5) In MATLAB, without using sort, implement the following function so that it performs as specfied: function a = compare1 ( s1 , s 2 ) % s1 and s2 are s t r i n g s % I f s1 comes before or is equal to s2 in t h e ASCII d i c t i o n a r y % order , t hen a i s 1 . Otherwise , a is 0 . Case is ignored. Here are some helpful implementation tips. (1) Pad the shorter string with blanks, i.e., add trailing blanks to make the two strings the same length. This will not affect the outcome. (2) Find the smallest integer k so that s1(k) is different than s2(k). Use a while-loop. If no such index exists, then the two strings are the same. (3) The value of a is one if and only if s1(k) <= s2(k) is true.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started