Page 105 - Basics of MATLAB and Beyond
P. 105

a(:,:,3)  =
                                    3     3      3
                                    3     3      3
                                    3     3      3
                               Indexing for multidimensional arrays works in the same way as two-
                               dimensional arrays;
                               >> a(2,:,1)
                               ans  =
                                    4     5      6
                               >> a(2,:,2)
                               ans  =
                                    8    10     12
                               >> a(2,:,:)
                               ans(:,:,1)   =
                                    4     5      6
                               ans(:,:,2)   =
                                    8    10     12
                               ans(:,:,3)   =
                                    3     3      3
                               Data can be removed from multidimensional arrays by using the empty
                               matrix:

                               >> a(:,:,2) = []
                               a(:,:,1)  =
                                    1     2      3
                                    4     5      6
                                    7     8      9
                               a(:,:,2)  =
                                    3     3      3
                                    3     3      3
                                    3     3      3
                               Elements can be columnarly extracted from multidimensional arrays in
                               the same way as they are from two-dimensional arrays:
                               >> a(:)’
                               ans  =
                                 Columns 1 through 12
                                    1   4    7   2   5   8   3    6   9   3   3   3
                                 Columns 13through 18
                                    3   3    3   3   3   3

                               29.1   Generating Multidimensional Grids
                               The function meshgrid can be used to create matrices representing
                               evenly-spaced grids of points.



                               c   2000 by CRC Press LLC
   100   101   102   103   104   105   106   107   108   109   110