User`s manual
6 Importing and Exporting Data
6-4
computer-readable form and you have to type it in. Essentially the same as
the first method, this method has the advantage of allowing you to use your
editor to change the data and correct mistakes. You can then just rerun your
M-file to re-enter the data.
•
Load data from an ASCII flat file.
A flat file stores the data in ASCII form, with fixed-length rows terminated
with new lines (carriage returns) and with spaces separating the numbers.
You can edit ASCII flat files using a normal text editor. Flat files can be read
directly into MATLAB using the
load command. The result is to create a
variable with the same name as the filename.
See the
load function reference page for more information.
•
Read data using MATLAB’s I/O functions.
You can read data using fopen, fread, and MATLAB’s other low-level I/O
functions. This method is useful for loading data files from other applications
that have their own established file formats.
•
Write a MEX-file to read the data.
This is the method of choice if subroutines are already available for reading
data files from other applications. See the section, “Introducing MEX-Files”
on page 1-3, for more information.
•
Write a program to translate your data.
You can write a program in C or Fortran to translate your data into MAT-file
format. You can then read the MAT-file into MATLAB using the
load
command. Refer to the section, “Reading and Writing MAT-Files” on
page 6-6, for more information.
Exporting Data from MATLAB
There are several methods for getting MATLAB data back to the outside world:
•
Create a diary file.
For small matrices, use the diary command to create a diary file and display
the variables, echoing them into this file. You can use your text editor to
manipulate the diary file at a later time. The output of
diary includes the
MATLAB commands used during the session, which is useful for inclusion
into documents and reports.