Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help >  programs >  matlab

Matlab - File Input and Formatted Output

[Introduction] [File opening and closing] [Output] [Input]

Introduction

Matlab has routines to read and write ASCII files. People who've use C's file handling routines should find the methods familiar, though even then there are surprises.

Note that for particular formats there are specialised routines - xmlread and xmlwrite for XML files, and various Spreadsheet/database routines

File opening and closing

For details, see

Output

Output's usually simpler than input because less error handling's needed. save is easier to use, though fprintf offers more control. For details, see

Input

textread tries to read a whole file, which might be ok if all the lines in the file have the same format. fscanf can also read a whole file, though it can read less if you want. fgetl and fgets read a line at a time For details and further examples, see See also Mathworks' File I/O Guide.
© Cambridge University Engineering Dept
Information provided by Tim Love (tpl)
Last updated: April 2008