how to find most common words in text by matlab

bita hallajia · Apr 12, 2022 · 1.9K views
Question
how to tag POS on nouns and verbs in MATLAB, Is it related to regular expressions? I know that regular expressions find a pattern in a text, but I want to find the most common words in texts and tag POS on them( I mean the words are nouns or verbs) and then exchange that POS and make an unfamiliar pair of words. how can I find the most common words in texts by MATLAB?is there any solution for that or I should use another software?
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 20, 2026

Finding the most common words is easy with Text Analytics Toolbox:

 

>> sonnets = extractFileText("sonnets.txt");
>> sonnets = erasePunctuation(sonnets);
>> tokenizedSonnets = tokenizedDocument(lower(sonnets));
>> bag = bagOfWords(tokenizedSonnets);
>> topkwords(bag, 10)

ans =

    10×2 table

       Word     Count
      ______    _____

      "and"      490 
      "the"      436 
      "to"       409 
      "my"       371 
      "of"       370 
      "i"        344 
      "in"       321 
      "that"     320 
      "thy"      281 
      "thou"     234

You probably want to remove some words (check out removeWords and stopWords). POS tagging is supported in release R2018b and later.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!