IN MATHLAB PROGRAM Write a function which you read a text file called ”csulb.txt
ID: 2082077 • Letter: I
Question
IN MATHLAB PROGRAM
Write a function which you read a text file called ”csulb.txt” and read all text as words. Assume that it will have following text!
California State University, Long Beach (CSULB; also known as Long Beach State, Cal State Long Beach, LBSU, or The Beach) is the third largest campus of the 23- school California State University system (CSU) and one of the largest universities in the state of California by enrollment, its student body numbering 37,776 for the Fall 2016 semester. As of Fall 2014, the school had 2,283 total faculty, with 36.7 percent of those faculty on the tenure track. With 5,286 graduate students, the university enrolls one of the largest graduate student populations across the CSU and in the state of California alone. The university is located in the Los Altos neighborhood of Long Beach at the southeastern coastal tip of Los Angeles County, less than one mile from the border with Orange County. The university offers 82 different Bachelor's degrees, 65 types of Master's degrees, four Doctoral degrees..
• Nowthefunctionwillreturnthenumberofoccurrenceofaspeificwordthatis taken as an input of this function. For example if the functioname is “findTextCSULB”.. Then
findtextCSULB (‘of’) will return 11
Explanation / Answer
% the input file contains only 10 'of'
% findTextCSULB('the',1) will return 17 for CAPS insensitive test
% findTextCSULB('the',0) will return 14 for CAPS sensitive test
% input file name is 'csulb.txt
function Count = findTextCSULB(STRING1,CAPSinsensitive)
STRINGsmall = lower(STRING1);
text = fileread('csulb.txt');
nWords = numel(strsplit(text));
words = strsplit(text);
words_char = char(words);
words_char_size = size(words_char);
No_of_words = words_char_size(1);
chaword_length_max = words_char_size(2);
Count = 0;
for W = 1:No_of_words
temP_word = words_char(W,1:chaword_length_max);
r1=strrep(temP_word,' ','');
r2=strrep(r1,'(', '' );
r3=strrep(r2,')', '' );
r3Lower = lower(r3);
if(CAPSinsensitive==1)
if strcmp(r3Lower,STRINGsmall)
Count = Count + 1;
end
else
if strcmp(r3,STRING1)
Count = Count + 1;
end
end
end
end