Question: MatLab Write a function with the header: function [wordcount] = myWordCounter (fid, keyword ) which takes a file pointer to a text file and a
![MatLab Write a function with the header: function [wordcount] = myWordCounter](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f31da66c6bf_87066f31da607c23.jpg)
MatLab
Write a function with the header: function [wordcount] = myWordCounter (fid, keyword ) which takes a file pointer to a text file and a keyword and reads each line of the text file, counting every instance of the keyword. The function returns wordCount which is the total number of occurrences of keyword in the text file. Note that to pass a file pointer, you must create one as shown in the test cases below, and be sure to close it (as shown) afterwards so that the file may be reopened. Note that the function should NOT be case sensitive but should also find instances of words which contain keyword (e.g., it should count "there" when keyword is "the"). Sample text files GettingAhead.txt and Passion.txt are provided HINT: lookup (via Matlab help and Google) built-in function "feof" and "fget NOTE: Your fid value will be different than what is shown here. Matlab will simply choose the next available integer not used by another file handle. A value of "1" however, means Matlab was unable to open the file, probably because the place you stored it is nof in the Matlab path Test Cases: >> fid = fopen ( ' GettingAhead . txt ' , >> n = myWordcounter (fid, 'skill') ' r ' ) ; n a >>fclose (fid); >> fid fopen ( ' GettingAhead . txt ' , >> n = myWordcounter (fid, 'Sk11L') ' r ' ) ; n F
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
