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

In one single matlab script file In one single matlab script file (exercise01.m)

ID: 3842377 • Letter: I

Question

In one single matlab script file

In one single matlab script file (exercise01.m), implement: Create a variable, A, whose value is the string 'hello'; Create a cell array, C, containing the strings: 'hello' 'goodbye' 'hello' 'hello goodbye' 'goodbye' 'hello' 'goodhellow' 'see you in hell'. Each index in your cell array should contain one of these strings. Note, you can create an empty cell array by setting it to an empty cell, e.g. C = []; and you can add a string to the end of a cell array by e.g. C{end + 1} = 'hello'; Write code to count how many times the (exact) string 'hello' occurs in your array. Now write code to count how many times the word hello occurs in your array. Useful functions: for, find, strcmp, isempty, strfind. Write code to find the most similar string to 'goodfellow' in your array (where similarity is measured as the number of letters in common). Useful function: intersect.

Explanation / Answer

A = 'hello';

C = [];
C {end + 1} = 'hello';
C {end + 1} = 'goodbye';
C {end + 1} = 'hello';
C {end + 1} = 'hello goodbye';
C {end + 1} = 'goodbye';
C {end + 1} = 'hello';
C {end + 1} = 'goodbyehellow';

count = 0;
for i = 1:size(C)(2)
    if strfind(C{i},A) > 0 %%strfind returns the index from which the substring starts
        count ++;
    end
end
count


B = 'goodhellow';
min = length(intersect(C{1}, B)); %%intersect returns the common characters in two strings
index = 1;
for i = 2:size(C)(2)
    if length(intersect(C{i},B)) > min
        min = length(intersect(C{i},B));
        index = i;
    end
end
fprintf("Nearest word is %s ",C{index});

Hello champ! I tried my best ot keep the code as simple as possible. If you face any difficulty with the code, please let me know. I shall try by best to resolve all the issues you face.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote