Page 149 - Basics of MATLAB and Beyond
P. 149

Callbacks are fastest when they are implemented as function calls;
                               do not implement your callbacks as script m-files or as an eval of a
                               string. The reason is that matlab compiles a function the first time it
                               is encountered, whereas m-files and evals are interpreted line by line.
                                  The button-style uicontrols (pushbuttons, radiobuttons, and check-
                               boxes) are used by simply clicking on them with the mouse. Others
                               need more interaction: you must choose an item from a list (listboxes or
                               popupmenus) or specify a numeric value (sliders) or type in text (edit
                               boxes). We discuss briefly the operation of each of these different kinds
                               of uicontrols.

                               34.2   UIControls

                               Edit Boxes
                               Edit boxes are designed to read in a piece of typed text. The text inside
                               an Edit box is accessed via the box’s String property:
                               h = uicontrol(’style’,’edit’,’String’,’Hello’);

                               You can change it using the set command:
                               set(h,’string’,’Bye’)
                               or you can click in the box and change it by typing something else. You
                               can access what has been typed into an edit box by getting its string
                               property. After typing qwe into the box you can type:
                                           >> get(h,’string’)
                                           ans   =
                                           qwe
                               Numbers typed into edit boxes remain strings until you convert them to
                               numbers:
                                           >> x = get(h,’string’)
                                           x   =
                                           10.3
                                           >> x+1
                                           ans   =
                                                50    49    47    52
                                           >> str2num(x) + 1
                                           ans   =
                                               11.3000
                               Text

                               Good GUIs have instructive text that indicates the function of a uicon-
                               trol. These can be placed with the text-style uicontrol. In the following
                               GUIthe “Name:”, “Address:”, and “Sex:” labels are three separate
                               uicontrols of Text style.



                               c   2000 by CRC Press LLC
   144   145   146   147   148   149   150   151   152   153   154