Page 102 - Basics of MATLAB and Beyond
P. 102

>> meteo.Temperature
                               ans  =
                                   24
                               ans  =
                                  19.0000    16.5000   15.3000
                               We can capture this output in a cell array as follows:
                               >> q = {meteo.Temperature}
                               q=
                                   [24]     [1x3double]
                               Or, we can string them together in a single array by enclosing the
                               meteo.Temperature expression in square brackets:

                               >> q = [meteo.Temperature]
                               q  =
                                  24.0000    19.0000   16.5000    15.3000
                               In this way you can operate on all elements of a field at once. For
                               example, to calculate the mean of all the temperature measurements:

                               >> mean([meteo.Temperature])
                               ans  =
                                  18.7000

                               28.2   Example: Capturing the List of Variables

                               Typing whos gives you a list of the variables present in the workspace,
                               along with their size, the number of bytes they occupy, and their class.
                               For example, create the following variables:
                               clear
                               a=1;
                               name = ’Jane Smythe’;
                               vect=[123];
                               acell = {1 2 ; ’big’ ’little’};
                               meteo = struct(’Site’,{’Adelaide’,’Sydney’});
                               The whos command produces the following list:
                               >> whos
                                 Name         Size         Bytes   Class
                                 a            1x1              8   double array
                                 acell        2x2            402   cell array
                                 meteo        1x2            244   struct array
                                 name         1x11            22   char array
                                 vect         1x324                double array
                               Grand total is 58 elements using 1396 bytes



                               c   2000 by CRC Press LLC
   97   98   99   100   101   102   103   104   105   106   107