Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matlab GUIs GUIDE.

Similar presentations


Presentation on theme: "Matlab GUIs GUIDE."— 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',[ ]); pbh1 = uicontrol(ph,'Style','pushbutton','String','Button 1',... 'Units','normalized',... 'Position',[ ]); pbh2 = uicontrol(ph,'Style','pushbutton','String','Button 2',... 'Position',[ ]);

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 plotitall %function defined later in the script
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',[ ]);

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',[ ]) 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',[ ]);

21 Pop-up menus (drop down menus) open to display a list of choices
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',[ ]); Pop-up menus (drop down menus) open to display a list of choices pmh = uicontrol(fh,'Style','popupmenu',...

22 uicontrol Push buttons generate an action when clicked pbh = uicontrol(fh,'Style','pushbutton','String','Button 1',... 'Position',[ ]); 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',[ ]);

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',[ ],... 'Position',[ ]); Static text controls display lines of text; typically used to label other controls sth = uicontrol(fh,'Style','text',... 'String','Select a data set.',... 'Position',[ ]);

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',[ ]);

25 uitable: Callbacks are fired when table cells are selected or edited
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)


Download ppt "Matlab GUIs GUIDE."

Similar presentations


Ads by Google