If someone could code this Matlab I would greatly appreciate
If someone could code this (Matlab) I would greatly appreciate it. I need every step.
18) (15 points) For Loops 18) (15 points) For Loops: You are wanting to identify how close two word se two words are by incorporating a for- loop using the following algorithnm 1. First determine whether or not the two words are the same length 2. If the words are different lengths, then output the difference of the tw 3. If the words are the same length, then step through the letters of each word u the two lengths and exit ers of each word using a for-loop and identify the number of characters that are mismatched. For example, the word and bag have 1 mismatch whereas bag and bag have and the number of mismatches. s bat 0 mismatches. Output the two words Be sure to record your answer on the answer sheet, not your test Beginning Code: word1- input(\'Enter first word\', \'s\'); word2 = input(\'Enter second word\', \'s\'); mismatches = 0; if (ee fa (word!)-=len,3th(word 2) nia (asorloothlword 2) Solution
word1 = input(\'Enter first word: \',\'s\');
word2 = input(\'Enter second word: \',\'s\');
mismatches = 0;
%first determine whether or not the two words are the same length
lengthOfWord1 = size( word1, 2 );
lengthOfWord2 = size( word2, 2 );
if lengthOfWord1 ~= lengthOfWord2
fprintf(\'%d\ \', abs( lengthOfWord1 - lengthOfWord2 ) );
else
%length of both words are same
%find number of mismatches
for i=1:lengthOfWord1
if word1(1,i) ~= word2(1,i)
mismatches = mismatches + 1;
end
end
fprintf(\'words are: %s and %s\ \', word1, word2);
fprintf(\'Number of mismatches: %d\ \',mismatches);
end
