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

% Function Name: wordFind % Inputs (2): - (char) An array of random characters %

ID: 3558000 • Letter: #

Question

% Function Name: wordFind % Inputs (2): - (char) An array of random characters % (char) A string to find % Outputs (1): - (char) A formatted string regarding the location of the % word % % Function Description: % This function works just like word search books where you find a word % in a group of letters. This function takes a grid of letters as its % first input and searches for the second input within that grid. The % words will only appear vertically or horizontally (not diagonally). % It can appear in reverse direction as well (right to left or down to % up). The word does not have to appear in the grid. % % The output should be formatted as follows if the string is found: % % out => 'The word starts in column , row , % and goes .' % % NOTE: The string is all one line, but for ease of reading, it is two % lines in the directions above. % % - The column and row number should be formatted Numerically (1, 2, % etc. % - The directions should be right(as in left to right), left, % up(down to up), or down % - Ignore diagonal words % - Case does not matter % % If the string does not appear in the grid, then output the following: % out => 'The word does not exist.' % % Hints: % - You may NOT use the 'strfind' function in this problem. Doing so % will result in no credit. % - The word you are looking for will not appear multiple times in the % array. % % Test Cases: % % board = ['A','R','O','E','D'; % 'O','S','P','D','L'; % 'N','S','P','O','T'; % 'G','R','V','C','N'; % 'U','E','S','I','Q']; % % [a] = wordFind(board,'spot'); % a => 'The word starts in column 2, row 3, and goes right.' % % [a] = wordFind(board,'love'); % a => 'The word does not exist.' % % [a] = wordFind(board,'code'); % a => 'The word starts in column 4, row 4, and goes up.'

(this is what I have so far and I'm not sure if thats even right)

function locString = wordFind(array, string)

i = length(string)

horizontal = cellstr([array, array( : , end:-1:1);

vertical = cellstr([array' , array( :, end:-1:1);

Explanation / Answer

clc; clear all;
searchterm='word' ;
fid=fopen('notes.txt');
f=fscanf(fid,'%c');
[m n]=size(f);

inc=0;
wrdinc=1;
for chr=1:n
inc=inc+1;

if f(inc)==' ';
wordc{wrdinc}=f(1:inc-1);
f(1:inc)=[];
wrdinc=wrdinc+1;
inc=0;
end
end

[m n]=size(wordc);

for i=1:n
m=char(wordc{i});
if strcmp(wordc{i},searchterm)==1;
disp(['Word discovered appears as word number: ',num2str(i),' of ',num2str(n),' words !'])
disp(['Search term: ',wordc{i}])
if (i>1)
disp(['Word before search term: ',wordc{i-1}])
disp(['Word after search term: ',wordc{i+1}])
else
if i==1
disp(['Can not display the word before the searched term if the searched word is the first word'])
disp(['Word after search term: ',wordc{i+1}])
end

if i==n
disp(['Can not display the word after the searched term if the searched word is the last word'])
disp(['Word before search term: ',wordc{i-1}])
end


end
disp(['oOoOoOo'])
end
end