Main Content

Import Text Data into MATLAB

Use the following functions to import text data into MATLAB®. Usually, the easiest way to import text data into MATLAB is to use the extractFileText function. For example, to import text from a text file, use:

str = extractFileText('sonnets.txt');
This table outlines which function to use for different file types. For more information, see Extract Text Data from Files.

SourceFunctionExample
Text, Microsoft® Word, PDF, and HTML filesextractFileTextstr = extractFileText('sonnets.txt');
CSV and Microsoft Excel® filesreadtabletbl = readtable('factoryReports.csv','TextType','string');
HTML codeextractHTMLTextstr = extractHTMLText('<html><body><h1>THE SONNETS</h1><p>by William Shakespeare</p></body></html>');
PDF formsreadPDFFormDatadata = readPDFFormData('weatherReportForm1.pdf');

See Also

| | |

Related Topics