Page 97 - Basics of MATLAB and Beyond
P. 97

>> a(1,1) = {[1 2 3]}
                               a=
                                   [1x3double]
                               or

                               >> clear a
                               >> a{1,1} = [1 2 3]
                               a=
                                   [1x3double]

                               but not
                               >> clear a
                               >> a(1,1) = [1 2 3]
                               ???  In an assignment   A(matrix,matrix) = B, the number of
                               columns in B and the number of elements in the A column
                               index matrix must be the same.

                                  Cell arrays can contain other cell arrays. For example:
                               >> t = {’Fred Flintstone’ {[1 2 3] , spiral(3)}}
                               t=
                                   ’Fred Flintstone’     {1x2 cell}

                                  matlab’s default display of a cell array is in summary form, as in
                               the above examples. You can display the details using celldisp:

                               >> celldisp(t)
                               t{1}  =
                               Fred Flintstone
                               t{2}{1}  =
                                    1     2      3
                               t{2}{2}  =
                                    7     8      9
                                    6     1      2
                                    5     4      3
                               Or, you can get a graphical summary using cellplot:



                               cellplot(t)


                               The left-hand box is the first cell, containing the string ’Fred
                               Flintstone’. The right-hand box is the second cell containing a 1×2 cell
                               array whose cells contain the vector [123] and the matrix spiral(3),
                               respectively.



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