MATLAB HELP strings loops An anagram is a word or phrase for

MATLAB HELP

(strings, loops) An anagram is a word or phrase formed by rearranging the letters of another word or phrase. Examples include: listen – silent cinema – ice man a telescope – to see place Spaces obviously don’t count when determining if two sets of words are anagrams. Case doesn’t matter. Write a function called anagram.m that compares two strings and returns 1 (logical true) if they are anagrams, and 0 (logical false) if they are not. You can use any built-in functions you like (and no, there isn’t a built-in anagram function.)

Solution

function areAnagram = checkAnagram(str1, str2)
s1 = lower(str1)
s1( isspace(s1) ) = [] ;
s2 = lower(str2)
s2( isspace(s2) ) = [] ;
  
s1 = sort(s1)
s2 = sort(s2)
  
   areAnagram = 0
if (s1 == s2)
       areAnagram = 1
   end
end

disp(checkAnagram(\"abc def\", \"f e d a c b\"))

MATLAB HELP (strings, loops) An anagram is a word or phrase formed by rearranging the letters of another word or phrase. Examples include: listen – silent cinem

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site