12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Callbacks are fastest when they are implemented as function calls;do not implement your callbacks as script m-files or as an eval <strong>of</strong> astring. The reason is that matlab compiles a function the first time itis encountered, whereas m-files <strong>and</strong> evals are interpreted line by line.The button-style uicontrols (pushbuttons, radiobuttons, <strong>and</strong> checkboxes)are used by simply clicking on them with the mouse. Othersneed more interaction: you must choose an item from a list (listboxes orpopupmenus) or specify a numeric value (sliders) or type in text (editboxes). We discuss briefly the operation <strong>of</strong> each <strong>of</strong> these different kinds<strong>of</strong> uicontrols.34.2 UIControlsEdit BoxesEdit boxes are designed to read in a piece <strong>of</strong> typed text. The text insidean Edit box is accessed via the box’s String property:h = uicontrol(’style’,’edit’,’String’,’Hello’);You can change it using the set comm<strong>and</strong>:set(h,’string’,’Bye’)or you can click in the box <strong>and</strong> change it by typing something else. Youcan access what has been typed into an edit box by getting its stringproperty. After typing qwe into the box you can type:>> get(h,’string’)ans =qweNumbers typed into edit boxes remain strings until you convert them tonumbers:>> x = get(h,’string’)x =10.3>> x+1ans =50 49 47 52>> str2num(x) + 1ans =11.3000TextGood GUIs have instructive text that indicates the function <strong>of</strong> a uicontrol.These can be placed with the text-style uicontrol. In the followingGUIthe “Name:”, “Address:”, <strong>and</strong> “Sex:” labels are three separateuicontrols <strong>of</strong> Text style.c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!