1 / 25

Matlab GUIs

Matlab GUIs. GUIDE. Laying out the GUI. Use GUIDE. OpeningFcn. GUIDE is going to create a function called ‘ NameofGUI_OpeningFcn ’ This function takes 4 variables, in this order Handle to figure ( hObject ) e ventdata , which is not used A structure called handles

dermot
Download Presentation

Matlab GUIs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matlab GUIs GUIDE

  2. Laying out the GUI Use GUIDE

  3. OpeningFcn • GUIDE is going to create a function called ‘NameofGUI_OpeningFcn’ • This function takes 4 variables, in this order • Handle to figure (hObject) • eventdata, which is not used • A structure called handles • varargin, command line arguments to the GUI

  4. OpenFcn is the initialization function, and is where you would place basic information & global variables • For example, for simple_gui all of the original data set up falls under OpenFcn % Create the data to plot. handles.peaks=peaks(35); handles.membrane=membrane; [x,y] = meshgrid(-8:.5:8); r = sqrt(x.^2+y.^2) + eps; sinc = sin(r)./r; handles.sinc = sinc; % Set the current data value. handles.current_data = handles.peaks; surf(handles.current_data)

  5. Handles • guidata(object_handle,data) • stores the variable data as GUI data • Object_handle is usually the parent figure • Data can be any MATLAB variable but is usually a structure called handle when using GUIDE • If you modify the handle you have to resave it using guidata • Following on previous slide % Set the current data value. handles.current_data = handles.peaks; surf(handles.current_data) % Update handles structure guidata(hObject, handles);

  6. get and set • get – used to query handle graphics object properties • Useful in GUIs to figure out if radio buttons are on or off for example • set – used to set handle graphics object properties • Frequently used set the ‘String’ portion of the variables in the handle structure

  7. GUIDE • Use the GUIDE interface to move components around • To design the components, you open Property Inspector from the ‘View’ drop-down menu • ‘String’ is used to change the text associated with the component • ‘Tag’ is used to control the name of the Callback function associated with the component

  8. Available Components • (look at guide)

  9. Kinds of Callbacks (incomplete list) • ButtonDownFcn– executes when the GUI user presses a mouse button while the pointer is on or near a component or figure • Callback – Control action. Executes when a user clicks a push button or selects a menu item • ClickedCallback – Control action. Executes when the push tool or toggle tool is clicked.

  10. CreateFcn – Initializes the component when a function creates it. • DeleteFcn – Performs cleanup operations just before a component or figure is destroyed. • KeyPressFcn – Executes when the user presses a keyboard key and the callbacks’s component or figure as focus

  11. Panels and Button Groups • uipanel: Panels arrange GUI components into groups, making the interface easier to understand. ph = uipanel(fh,'PropertyName',PropertyValue,...) • uibuttongroup: Button groups are like panels but are used to manage exclusive selection behavior for radio buttons and toggle buttons bgh = uibuttongroup(fh,'PropertyName',PropertyValue,...)

  12. Panels and button groups are containers that arrange GUI components into groups. • If you move the panel or button group, its children move with it and maintain their positions relative to the panel or button group. • The panel or button group become the handle on calls to uicontrol

  13. ph = uipanel('Parent',fh,'Title','My Panel',... 'Position',[.25 .1 .5 .8]); pbh1 = uicontrol(ph,'Style','pushbutton','String','Button 1',... 'Units','normalized',... 'Position',[.1 .55 .8 .3]); pbh2 = uicontrol(ph,'Style','pushbutton','String','Button 2',... 'Units','normalized',... 'Position',[.1 .15 .8 .3]);

  14. Menu Bars • uimenu: add a menu bar (ie. File, Edit, View, etc) mh = uimenu(parent,'PropertyName',PropertyValue,...) Example: mh= uimenu(fh,'Label','My menu'); eh1 = uimenu(mh,'Label','Item 1'); eh2 = uimenu(mh,'Label','Item 2','Checked','on'); seh1 = uimenu(eh1,'Label','Choice 1','Accelerator','C',... 'Enable','off'); seh2 = uimenu(eh1,'Label','Choice 2','Accelerator','H')

  15. Reading in SAC data • Example we will look at is speedyseis • The sac reader in this case is a script (not a function) called get_sac, which sets variables • filename • npts • sampdelta • date • hour • minu • seco • data

  16. Speedyseis is written in GUIDE • It has a pushbutton called ‘Get Sac file’, which has the following callback % --- Executes on button press in getSACfilebutton. function getSACfilebutton_Callback(hObject, eventdata, handles) global hObject handles %get_sac reads sac file and puts data into workspace of calling program/routine %uses SAC_file_prompt for prompt, if it does not exist - uses default prompt % SAC_file_prompt='Select a SAC file'; get_sac

  17. Next we set some handles handles.filename=filename; handles.samprate=round(1/sampdelta); samprate_str=num2str(handles.samprate); set(handles.sampratedisplay,'String',samprate_str); handles.delt=1/handles.samprate; handles.fulldata=data; handles.fulldatalen=length(handles.fulldata);

  18. handles.fulldatend=length(handles.fulldata); handles.datstart=1; handles.datend=handles.fulldatalen; plotitall%function defined later in the script guidata(hObject, handles); %standard last line in a function in which handles%have been set or revised

  19. Available Components • axes: Axes enable your GUI to display graphics such as graphs and images using commands such as: plot, surf, line, bar, polar, pie, contour, and mesh. ah = axes('Parent',fh,'Position',[.15 .15 .7 .7]);

  20. uicontrol • Check boxes can generate an action when checked and indicate their state as checked or not checked. cbh = uicontrol(fh,'Style','checkbox',... 'String','Display file extension',... 'Value',1,'Position',[30 20 130 20]) • Edit text components are fields that enable users to enter or modify text strings. eth = uicontrol(fh,'Style','edit',... 'String','Enter your name here.',... 'Position',[30 50 130 20]);

  21. uicontrol • List boxes display items and enable users to select one or more items lbh = uicontrol(fh,'Style','listbox',... 'String',{'one','two','three','four'},... 'Value',1,'Position',[30 80 130 20]); • Pop-up menus (drop down menus) open to display a list of choices pmh = uicontrol(fh,'Style','popupmenu',... 'String',{'one','two','three','four'},... 'Value',1,'Position',[30 80 130 20]);

  22. uicontrol • Push buttons generate an action when clicked pbh = uicontrol(fh,'Style','pushbutton','String','Button 1',... 'Position',[50 20 60 40]); • Radio buttons are similar to check boxes, but are typically mutually exclusive within a group of related radio buttons. Use button groups to manage related radio buttons rbh = uicontrol(fh,'Style','radiobutton',... 'String','Indent nested functions.',... 'Value',1,'Position',[30 20 150 20]);

  23. uicontrol • Sliders accept numeric input within a specified range by enabling the user to move a sliding bar sh = uicontrol(fh,'Style','slider',... 'Max',100,'Min',0,'Value',25,... 'SliderStep',[0.05 0.2],... 'Position',[30 20 150 30]); • Static text controls display lines of text; typically used to label other controls sth = uicontrol(fh,'Style','text',... 'String','Select a data set.',... 'Position',[30 50 130 20]);

  24. uicontrol • Toggle buttons generate an action and indicate whether they are turned on or off. tbh = uicontrol(fh,'Style','togglebutton',... 'String','Left/Right Tile',... 'Value',0,'Position',[30 20 100 30]);

  25. uitable: Callbacks are fired when table cells are selected or edited. Tables can be made to be user editable. th = uitable(fh,'Data',magic(5)); tpos= get(th,'Position’) texn= get(th,'Extent’) tpos(3) = texn(3); tpos(4) = texn(4); set(th, 'Position’, tpos)

More Related