Count word except some special case
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Count the number of words in a string, excluding the article (a, an, the), regardless of capitalization. Demonstrate the working of your code with an example string.
2 Kommentare
Adam Danz
am 8 Dez. 2021
This is clearly a homework assignment. You also haven't asked a question.
Show us what you've got and ask a specific question about the step where you're stuck. Don't ask people to do your homework for you.
Antworten (1)
Chunru
am 9 Dez. 2021
x ='some text here with a and an and the';
% you can use "lower" to convert it into lower case
%
% consider "split" to split the string into words with appropriate
% delimiters
%
% consider "ismember" to test the split words belong to "a" "an" and "the"
% idx = ~ismember(splitwords, {'a', 'an', 'the'})
% "sum" up idx to get the number of words
% n = sum(idx)
3 Kommentare
Adam Danz
am 9 Dez. 2021
Instead of handeling upper and lower cases separately, force the text to be upper or lower case.
Example:
x = 'A thesis is an example of The Program';
lower(x)
upper(x)
Use Chunru's advice to split the sentence into words and use ismember to determine which words match the exclusion list (a,an,the). The list should match the case you choose.
Chunru
am 10 Dez. 2021
x = 'A thesis is an example of The Program';
x = lower(x)
splitwords = split(x, {' ', '.', ',', ':', '?', '!'})
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!