MATLAB: How to read a text file and then take out specific words in that text file

fileforloopMATLABMATLAB and Simulink Student Suitestrgsplittext;

lets say I have to read a text file, then take out specific words and create a program that counts the number of words taken out, how would one do that?

Best Answer

fid = fopen(filename);
T = textscan(fid, '%s');
T = T{1};
fclose(fid);
idx = strcmp(T, 'word_to_take_out');
Nword_to_take_out = nnz(idx);
T(idx) = []; % remove from T