External Interfaces/API |
|
Importing Data to MATLAB
You can introduce data from other programs into MATLAB by several methods. The best method for importing data depends on how much data there is, whether the data is already in machine-readable form, and what format the data is in. Here are some choices. Select the one that best meets your needs.
- Enter the data as an explicit list of elements.
- If you have a small amount of data, less than 10-15 elements, it is easy to type the data explicitly using brackets [ ]. This method is awkward for larger amounts of data because you can't edit your input if you make a mistake.
- Create data in an M-file.
- Use your text editor to create an M-file that enters your data as an explicit list of elements. This method is useful when the data isn't already in 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.
- Read data using MATLAB I/O functions.
- You can read data using
fopen
, fread
, and MATLAB 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, 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, for more information.
| Using MAT-Files | | Exporting Data from MATLAB | |