Page 114 - Basics of MATLAB and Beyond
P. 114

name
                               >> staff(2,1,2).name(5:9)
                               ans  =
                               Blogg


                               30    Saving and Loading Data

                               30.1   MATLAB Format

                               matlab’s internal standard for saving and loading data is the mat-file.
                               The save command saves all the variables in the workspace to a disk file
                               called matlab.mat:

                               >>a=1;
                               >> b = 1:10;
                               >> str = ’hello’;
                               >> save
                               Saving to: matlab.mat

                               To save in a file with a different name, type:
                               save saved_data
                               To save only some of the variables, add their names:

                               save saved_data a b

                               Mat-files are binary files whose format is described fully in the mat-
                               lab documentation. Such a file is fully portable to matlab running on
                               another kind of computer. Information about the kind of computer that
                               matlab was running on when it saved the data is stored along with the
                               data. When matlab reads in a mat-file, it checks the type of computer
                               that the data were saved on and automatically performs any required
                               manipulations (byte swapping, for example).
                                  To load data from mat-files use the load command:
                               >> clear
                               >>a=1;
                               >> b = 1:10;
                               >> str = ’hello’;
                               >> save saved_data
                               >> clear
                               >> whos
                               >> load saved_data








                               c   2000 by CRC Press LLC
   109   110   111   112   113   114   115   116   117   118   119