Opening the book…
There is not one file I/O command that is best for every situation. The best choice depends on the file and what you need to do with it.
|
Situation |
Good choice |
Why |
|
Plain numeric data with equal columns on every row |
load / save or readmatrix / writematrix |
Simple and efficient |
|
Mixed text and numeric data in a text file |
textscan or readcell |
Can handle different data types |
|
Need to inspect or process each line individually |
fgetl |
Reads one line at a time |
|
Need carefully formatted output |
fprintf |
Controls spacing, decimals, labels, and line breaks |
|
Spreadsheet with mostly numbers |
readmatrix / writematrix |
Reads and writes numeric arrays |
|
Spreadsheet with mixed data |
readcell or readtable / writecell or writetable |
Handles labels, text, and numbers |
This page titled 9.11: Choosing the Right File I/O Tool was last modified on Tue, 30 Jun 2026 02:12:03 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.