Page 98 - Basics of MATLAB and Beyond
P. 98

To index nested cell arrays, use as many sets of curly brackets { and
                               } as needed to get you to the level of nesting required, then use round
                               brackets ( and ) to access their contents. For example:
                               >> tt = {t   {’Barney Rubble’ {[-1 1] , ’Bedrock’}}}
                               tt =
                                   {1x2 cell}
                                   {1x2 cell}
                               >> cellplot(tt)
























                               >> tt{2}
                               ans =
                                   ’Barney Rubble’     {1x2 cell}
                               >> tt{2}{2}
                               ans =
                                   [1x2 double]     ’Bedrock’
                               >> tt{2}{2}{1}
                               ans  =
                                   -1     1
                               >>  tt{2}{2}{2}
                               ans  =
                               Bedrock
                               >> tt{2}{2}{1}{2}
                               ??? Cell contents reference from a non-cell array object.

                               >> tt{2}{2}{1}(2)
                               ans  =
                                    1
                                    Exercise 11 Do you know where the word “stuck” has come
                                    from in the following example (answer on page 189):



                               c   2000 by CRC Press LLC
   93   94   95   96   97   98   99   100   101   102   103