I need to write a program in matlab that searches for specific key words in a text file and then Count the number of this specific word in text.
How can I search a text file for Count specific words using matlab?
501 views Asked by eman At
2
There are 2 answers
0
On
Matlab actually has a function strfind
which can do this for you. Check the Mathworks doc for more details.
The content of the text file should be stored in a variable:
text = fileread('filename.txt')
First look at how to read a text file using Matlab, then read the entire data into a cell array using
textscan
function which is an in-built function in Matlab and compare each element of the array with specific keyword usingstrcmp
.I have provided a function that takes filename and keyword as input and outputs the count of keywords present in the file.