Page 34 - Basics of MATLAB and Beyond
P. 34

max returns a vector containing the maximum value of each column.
                               When given a vector, max returns the maximum value:

                               >> max(m)
                               ans  =
                                    9
                               To find the index corresponding to the maximum value, supply two out-
                               put arguments to max:
                               >> [v,ind] = max(m)
                               v  =
                                    9
                               ind  =
                                    2

                               The first argument is the maximum value and the second is the index of
                               the maximum value. Another example is
                               >> x = 0:.01:2;
                               >> y = humps(x);
                               >> plot(x,y)
                               >> [v,ind] = max(y)
                               v  =
                                  96.5000
                               ind  =
                                   31
                               >> hold on
                               >> plot(x(ind),y(ind),’ro’)
                               >> x(ind)
                               ans  =
                                   0.3000
                               >> y(ind)
                               ans  =
                                  96.5000

                                  The find function is often used with relational and logical operators:

                                       Relational operators  ==  equal to
                                                           ~=   not equal to
                                                            <   less than
                                                            >   greater than
                                                           <=   less than or equal to
                                                           >=   greater than or equal to








                               c   2000 by CRC Press LLC
   29   30   31   32   33   34   35   36   37   38   39