Page 124 - Basics of MATLAB and Beyond
P. 124

text(-.7,f(-.7),’f(X)’)




                               But we have made a mistake: the “x” should be lower case. We try to
                               correct it by issuing another text command with a lower case “x”:





                               text(-.7,f(-.7),’f(x)’)




                               But this has printed over the top of the previous label, making a mess.
                               Without starting again, we can use the delete function to delete the
                               text objects, once we know their handles. We can get a list of the handles
                               of the line and the text objects by getting all the children of the current
                               axes:
                               >> h = get(gca,’children’)
                               h  =
                                  19.0001
                                  18.0001
                                  11.0005

                               The variable h is a three-element column vector (the actual values are
                               not important). These are the handles corresponding to the Line object
                               (parabola) and the two Text objects. But which of them is the Line
                               object and which are the Text objects? We can get the object types
                               corresponding to these handles by typing:
                               >> types = get(h,’type’)
                               types =
                                   ’text’
                                   ’text’
                                   ’line’

                               (The variable types is returned as a cell array.) A parent’s children
                               are always listed in reverse age order: the most recently drawn object
                               appears first—youngest first, oldest last. This tells us that the first two
                               elements of the vector h correspond to the text objects ‘f(X)’ and ‘f(x)’,
                               in that order, and the third element corresponds to the parabolic line.
                               We can delete the two text objects by typing:




                               c   2000 by CRC Press LLC
   119   120   121   122   123   124   125   126   127   128   129