Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB HELP -- NOT JAVA An anagram is a word or phrase formed by rearranging the

ID: 3783561 • Letter: M

Question

MATLAB HELP -- NOT JAVA

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.) Examples: >> r = anagram('dormitory', 'dirty room') r = 1 >> r = anagram('yes', no') r = 0 >> r = anagram('dog', 'cat') r = 0 >> r = anagram('conversation', 'conservation') r = 1

Explanation / Answer

function an=first(s1,s2)
tr=length(s1)
tr2=length(s2)
for i=1:tr
for j=1:tr2
if strcmp(s1(i),s2(j))
break;
end
end
if j == tr2
break;
end
end
if (tr2-i) ==0
an=1;
else
an=0;
end
end

>>first('yes','eys')

an =

1