Page 115 - Basics of MATLAB and Beyond
P. 115

>> whos
                                 Name       Size         Bytes  Class
                                 a          1x1              8  double array
                                 b          1x10            80  double array
                                 str        1x5             10  char array
                               Grand total is 16 elements using 98 bytes

                               >> a
                               a  =
                                    1
                               >> b
                               b  =
                                    1    2     3    4    5    6     7    8    9   10
                               >> str
                               str  =
                               hello

                               To save the data as readable text use the -ascii switch:
                               save saved_data_text -ascii

                               In this case the ‘.mat’ extension is not appended to the file name. The
                               ascii format is best kept for simple cases where your data is in the form
                               of a matrix (or vector or scalar). For example, in this case we have saved
                               the variables a, b, and c in a file that has the following contents:

                                  1.0000000e+00
                                  1.0000000e+00    2.0000000e+00    3.0000000e+00    ...
                                  1.0400000e+02    1.0100000e+02    1.0800000e+02    ...
                               The first line is the variable a, the second line is the variable
                               b = [1 2 ... 10], and the third line is the string str = ’hello’ con-
                               verted to its corresponding ascii values:

                               >> double(str)
                               ans  =
                                  104   101    108   108   111
                               If you try to load this data using the load command you will get an error
                               message because the lines have different numbers of values. To load an
                               ascii file like this, you’ll have to write your own loading function using
                               the functions getl etc. described in the next section. If you save an
                               ascii matrix, however, you can load it in again without difficulty:

                               >> clear
                               >> q = spiral(3)






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