Page 200 - Basics of MATLAB and Beyond
P. 200

33 !       36 $        39 ’        42 *       45 -        48 0
                               34 "       37 %        40 (        43 +       46 .        49 1
                               35 #       38 &        41 )        44 ,       47 /        50 2

                               Typing char(7) rings the bell.


                               Exercise 9 (Page 80)
                               The strvcat function is used instead of char because it ignores empty
                               strings in the input; the char function doesn’t:
                               >> char(’’,’The’,’’,’quick’)
                               ans =

                               The

                               quick
                               >> strvcat(’’,’The’,’’,’quick’)
                               ans =
                               The
                               quick
                               If char were used instead of strvcat, the result would always begin with
                               a blank line.

                               Exercise 10 (Page 83)
                               The problem is to deal with the two cases: (1) where the name of a
                               function or m-file is given, such as ‘sin’, and (2) where the function itself
                               is given, such as ‘sin(x)’. The difference here boils down to whether
                               the string input contains brackets or not (see hint). In other cases the
                               string input might not contain brackets, but would contain characters
                               used in defining a function, such as +, -, *, /,or . (as in t.^2). The
                               ascii values for these characters are all less than 48, so we detect the
                               presence of a function (rather than a function name) by checking the
                               input string for ascii values less than 48. If this is the case, we make
                               the input string into an inline function before passing it to feval:
                               function funplot(f,lims)

                               % Simple function plotter.

                               % Test for characters whose presence would imply that f
                               % is a function (not a function name):
                               if any(f<48)
                                 f = inline(f);
                               end


                               c   2000 by CRC Press LLC
   195   196   197   198   199   200   201   202   203   204   205