Page 100 - Basics of MATLAB and Beyond
P. 100

28.1   Example: Meteorological Database
                               In this example we create a structure using the struct function. We
                               create a meteorological observation database as follows:

                               meteo = struct(’Site’,{’Adelaide’,’Sydney’},...
                                               ’Time’,{2.34},...
                                               ’Temperature’,{24 19},...
                                               ’Pressure’,{10231015})

                               This structure consists of temperature and pressure measurements at
                               two different times at Sydney and Adelaide. The Adelaide data was
                               taken at 2:30:
                               >> meteo(1)
                               ans =
                                          Site: ’Adelaide’
                                          Time: 2.3000
                                   Temperature: 24
                                      Pressure: 1023
                               and the Sydney data was taken at 4:00:
                               >> meteo(2)
                               ans =
                                          Site: ’Sydney’
                                          Time: 4
                                   Temperature: 19
                                      Pressure: 1015
                               Let us suppose we have some new Sydney data taken at 8:00 and 11:00.
                               We add this as follows:
                               >> meteo(2).Time(2:3) = [8 11];
                               >> meteo(2).Temperature(2:3) = [16.5 15.3]
                               meteo =
                               1x2 struct array with fields:
                                   Site
                                   Time
                                   Temperature
                                   Pressure
                               >> meteo(2).Temperature
                               ans  =
                                  19.0000    16.5000   15.3000
                               The pressure meter broke so we do not have new pressure data for these
                               two new times. We could leave the pressure field with one entry, but
                               it might be better to indicate the absence of data more explicitly with
                               NaNs:



                               c   2000 by CRC Press LLC
   95   96   97   98   99   100   101   102   103   104   105