Page 153 - Basics of MATLAB and Beyond
P. 153

set(h,’string’,{’Red’;’Green’;’Blue’;...
                                   ’Pale Goldenrod’;’Orange’;’yellow’})


                               The item selected within the listbox is accessed via its “value” property.
                               For example, after selecting a colour from the list you can extract it
                               using the following commands:




                                                    >> str = get(h,’string’);
                                                   >> str(get(h,’value’))
                                                    ans =
                                                        ’Pale Goldenrod’




                               Popup menu
                               Popup menus are similar to listboxes in that they allow you to choose
                               from among a list of alternatives, but only one item is shown at a time;
                               the others become visible only when you press the button. Assuming
                               your listbox is still present from the previous example, you can convert
                               it to a popup menu by typing the following:

                               set(h,’style’,’popup’,...
                                     ’pos’,[168 219 145 32])

                               We changed the size (position) at the same time to make it look more like
                               a standard button. The user’s choice is accessed by the popup menu’s
                               “value” property, as for listboxes.

                               34.3   Exclusive Radio Buttons

                               Radio buttons can be used to offer a choice of one, and only one, item
                               from among alternatives. Think of a car radio with buttons for the
                               different radio channels: when you press one button in, the corresponding
                               channel only is selected. matlab’s radio buttons do not automatically
                               behave this way. You may want to allow more than one radio button to
                               be pressed at a time. But if you do want exclusive radio buttons you
                               must implement them with appropriate callbacks. One way to do it is
                               as follows:





                               c   2000 by CRC Press LLC
   148   149   150   151   152   153   154   155   156   157   158