Text read

Raheelanjum
3 min readDec 14, 2024

Textread is a function that handles many of the problems/tasks of file input for you. The syntax for textread is: "array_variable = textread( file_name );". The file name is a variable containing a string. Array_variable is a variable that will "receive" the contents of the file.

Text read

Matlab has a powerful built-in function that will read information out of a file and store it in an array. This function is called textread.

For example, to read a list of grades from a file called 'list_of_grades,' you would simply write:

The variable grades will be an array of numbers, one for each grade!

textread is a function that "takes in" the name of a file and "returns" an array of information.

The file should contain a column of data. (Note: textread can also read files with multiple columns of data).

Advanced Syntax

Textread takes several optional parameters that can be used to influence how it works. Below we discuss various situations you might encounter.

Textread is designed to read a list of numbers, one per line. Textread will also happily read a 'matrix' of numbers. Consider the following data file (named 'data' in the current folder):

--

--

Raheelanjum
Raheelanjum

Written by Raheelanjum

Highly skilled and experienced content writer dedicated to crafting compelling, informative content that resonates with diverse audiences. Expertise spans blog

Responses (18)