Converting a vertical text file into a character array for use in a Word Cloud

A
Aidan Lyons · Apr 9, 2022 · 1.9K views
Question
Im trying to read in this file so that it becomes a cell array of strings, so that I can combine with a cell array of corresponding occurances into a table for use in the wordcloud function. I can't seem to figure out how to read it in and manipulate it so that each word in the list is a string like a normal string cell array. Any suggestions? thanks
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 13, 2026
filename = 'YourFile.txt'
S = regexp( fileread(filename), '\r?\n', 'split');
S(cellfun(@isempty,S)) = [];    %remove empty lines, especially at the end

Now S will be a cell array of character vectors. It will not be a cell array of string objects because MATLAB uses either cell array of character vectors, or else uses string() arrays. You can convert it to a string array by using string(S)

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!