MATLAB: How to define the occurance of a word in a text

keywordtext file

Hi all,I need that code badly,I have a text'.txt'.I have chosen two words"are" and "the" which are repeated along the text so I need a code to read the text and if the word "are" comes put "1" and if the word "the" comes put "0" sequentially so a series of binary digits"x" is formed. for example x=1 0 0 1 1 1 1 0 that means "are" occurs first then "the"occurs twice then"are" four times then"the" and so on until the text ends.thanks

Best Answer

whichone = strcmp('and', lower(regexp(str, '(?<=^| )(([tT]he)|([aA]nd))(?=$| )', 'match')));
whichone is 1 for each occurrence of 'and' and 0 for each occurrence of 'the'