Download presentation
Presentation is loading. Please wait.
Published byΓλυκερία Μπότσαρης Modified over 5 years ago
1
Electrical and Computer Engineering Department SUNY – New Paltz
Computer Simulation “Lecture 11” Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz
2
Analysis of GUI Objects
mygui.m mygui.fig SUNY-New Paltz
3
Graphical User Interfaces (GUIs)
Objectives • figure files; • application M-files; • callback functions. SUNY-New Paltz
4
Basic structure of a GUI
GUIDE: Graphical User Interface Development Environment GUIDE: generates 2 files : FIG-file and application M-file SUNY-New Paltz
5
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
6
GUIDE SUNY-New Paltz
7
Inspect Properties String property
Tag property of the button is set to pushbutton1 Callback property myapp(’mybutton_Callback’,gcbo,[],guidata(gcbo)) SUNY-New Paltz
8
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
9
getting the time SUNY-New Paltz
10
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
11
Digital Clock SUNY-New Paltz
12
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
13
Square Root GUI SUNY-New Paltz
14
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
15
Plotting in a GUI SUNY-New Paltz
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.