Opening the book…
So far, many of our MATLAB examples have created data directly inside a script or in the Command Window. That works well when we are learning a new command or testing a small idea. But in real engineering work, data often comes from somewhere else.
For example, data may come from an experiment, a survey, a sensor, a spreadsheet, another computer program, or a previous MATLAB calculation. After MATLAB reads that data, we may process it, plot it, analyze it, or use it to make decisions. Then we often need to save the new results so that we can use them again later.
This process is called file input/output, or file I/O for short. Input means reading data from a file into MATLAB. Output means writing data from MATLAB to a file.
Think of a file as a container stored on your computer. MATLAB can open the container, read what is inside, add new information, or create a new container with results from your program.
A file can usually be used in three main ways:
- Read from the file: MATLAB imports data from the file into the workspace.
- Write to the file: MATLAB creates a new file or replaces the contents of an existing file.
- Append to the file: MATLAB adds new data to the end of an existing file without deleting the old data.
In this chapter, we will start with the simplest methods and then move to more flexible methods.
This page titled 9.2: Why File Input and Output Matters was last modified on Tue, 30 Jun 2026 02:12:02 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.
The book could not be loaded just now.