Electrical and Computer Engineering Department SUNY – New Paltz Computer Simulation “Lecture 11” Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz
Analysis of GUI Objects mygui.m mygui.fig SUNY-New Paltz
Graphical User Interfaces (GUIs) Objectives • figure files; • application M-files; • callback functions. SUNY-New Paltz
Basic structure of a GUI GUIDE: Graphical User Interface Development Environment GUIDE: generates 2 files : FIG-file and application M-file SUNY-New Paltz
Basic structure of a GUI FIG-file contains a complete description of the GUI figure application M-file contains the functions required to launch and control the GUI. Callback functions, written by you, determine the action taken when you interact with a GUI component SUNY-New Paltz
GUIDE SUNY-New Paltz
Inspect Properties String property Tag property of the button is set to pushbutton1 Callback property myapp(’mybutton_Callback’,gcbo,[],guidata(gcbo)) SUNY-New Paltz
My First GUI! Click on the run arrow In ‘mygui1.m’ file in the editor window, Find function: pushbutton1_Callback(hObject, eventdata, handles) In that function, change the ‘String’ property of the object to ‘Hello GUI!’ by adding: set(hObject, ‘String’, ‘Hello GUI!’) set(handles.push_button1, ‘String’, ‘Hello GUI’) Run the program In Command Window: Type ‘guide’ Select ‘Create New Guide’ Call your fig file ‘mygui1.fig’ Adjust the window size to a smaller one Drag a ‘pushbutton’ to the center Double click on it and find ‘String’ property. Rename it ‘Click Me!’ SUNY-New Paltz
getting the time SUNY-New Paltz
One Object affecting the other Place 2 push buttons on the scree Clicking the LHS button should change the background color of the RHS button Green. Clicking the RHS button should clear(back to the default the Green color. Hint use : Set(handles.pushbutton2, ..) to address the RHS button from the LHS call-back. SUNY-New Paltz
Digital Clock SUNY-New Paltz
Matlab Code % get time d = clock; % convert time to string time = sprintf( ’%02.0f:%02.0f:%02.0f’,d(4),d(5),d(6)); % change the String property of pushbutton1 set(gcbo,’String’,time) SUNY-New Paltz
Square Root GUI SUNY-New Paltz
MATLAB Code function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. a = str2num(get(handles.edit1,’String’)); x = a; % initial guess for i = 1:8 x = (x + a/x)/2; str(i) = {sprintf(’%g’,x)}; end set(handles.edit1,’String’,’’); set(handles.text2,’String’,str) SUNY-New Paltz
Plotting in a GUI SUNY-New Paltz