130 likes | 224 Views
Computer Simulation Lab. “Lecture 10”. Electrical and Computer Engineering Department SUNY – New Paltz. Graphical User Interfaces (GUIs). Objectives • figure files; • application M-files; • callback functions. Basic structure of a GUI. GUIDE:
E N D
Computer Simulation Lab “Lecture 10” Electrical and Computer Engineering Department SUNY – New Paltz 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
getting the time 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
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
Time and Date 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