You are on page 1of 1

Matlab Code:

clc;

clear all;

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';
c {end + 1} = 'see you in hell';
count = 0;
for i = 1:size(C)(2)
if strfind(C{i},A) > 0
count ++;
end
end
count

B = 'goodhellow';
min = length(intersect(C{1}, B));
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\n",C{index});

Output:

You might also like