EGR 115 Introduction to Computing for Engineers Graphical User Interface Design in MATLAB - Part 2 Monday 24 Nov 2014 EGR 115 Introduction to Computing.

Slides:



Advertisements
Similar presentations
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Advertisements

CS112 Scientific Computation Department of Computer Science Wellesley College Geese honk, but they don’t wave Sinusoidal waves.
Get number The ginput command creates crosshairs. When the user clicks the x,y values of the crosshairs are returned.
CS112 Scientific Computation Department of Computer Science Wellesley College Interactive Programs Graphical User Interfaces.
1 Computer Graphics Week7 -2D Rotation. 3-Rotation A shape can be rotated about any of the three axes. A rotation about the z-axis will actually rotate.
Programming a GUI Hanan sedaghat pisheh. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
A short intermission about function handles and cell arrays A MATLAB function may be referenced by a handle. >> sphere(100)
Introduction to the Graphical User Interface (GUI) in MATLAB
Matlab GUIs GUIDE.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Introduction to Matlab & Data Analysis
Rotations and Translations
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
MA/CS 3751 Fall 2002 Lecture 24. MA/CS 3752 ginput ginput is a Matlab function which takes one argument input: number of points to select in the image.
MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics.
Introduction to Matlab’s Graphical User Interface (GUI) Type “guide” “Guide” creates interface on a Figure window and code in an M-file. Some hidden code.
function varargout = MovieJoiner(varargin) % MOVIEJOINER M-file for MovieJoiner.fig % MOVIEJOINER, by itself, creates a new MOVIEJOINER or raises the.
Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces.
1 Computer Graphics Week9 -3D Geometric Transformation.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
SCARA – Forward Kinematics
Graphic User Interfaces (GUI) GUI provides a way to interact friendly with possibly complex programs. There are two types of GUI: - MDI: multiple document.
Introduction to Matlab & Data Analysis 2015 In this tutorial we will: Build a practical application using GUIDE Learn more about graphical user interface.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 4: Intro to Plotting Wednesday 10 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
EGR 115 Introduction to Computing for Engineers User-Defined Functions1 – Part 1 Wednesday 22 Oct 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers 3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
CS112 Scientific Computation Department of Computer Science Wellesley College Interactive Programs Graphical User Interfaces.
EGR 115 Introduction to Computing for Engineers
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 1 Wednesday 05 Nov 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 2 Friday 07 Nov 2014 EGR 115 Introduction to Computing for Engineers.
Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your.
Graphic User Interface Review of Lecture 1 to Lecture 6 C.F. Lu.
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
Handle Graphics and 1D Primitives Some Handel graphics.
CS112 Scientific Computation Department of Computer Science Wellesley College Blind to change More on GUIs.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 4 Monday 06 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 3 Monday 10 Nov 2014 EGR 115 Introduction to Computing for Engineers.
Graphical User Interfaces I The central station is the bubble gum planet with 280 pounds of clay and three head phone lines that come out and orbit the.
Lecture (7) Introduction to GUI Eng. Osama Talaat 1.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 3 Friday 17 Oct 2014 EGR 115 Introduction to Computing for Engineers.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
PATTERN RECOGNITION LAB 8 TA : Nouf Al-Harbi::
More Matlab Graphics and GUI Graphics subplots some useful commands 3D graphics GUI GUI controls The callback property Other essential properties.
Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)
Transformations of Shapes Translation by a vector Stretches Rotations around a point Reflections in the x- and y- axis Reflections in the line y = x and.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Graphical User Interfaces I
Reading and Writing Image Files
Topics Graphical User Interfaces Using the tkinter Module
Graphical User Interface in MATLAB
EGR 115 Introduction to Computing for Engineers
More on Graphical User Interfaces
MATLAB GUI with GUIDE 報告人:張捷勝.
Topics Graphical User Interfaces Using the tkinter Module
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

EGR 115 Introduction to Computing for Engineers Graphical User Interface Design in MATLAB - Part 2 Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers

Lecture Outline Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Graphical User Interface Design in MATLAB  A 3D animation inside a GUI Slide 2 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Lets create a more sophisticated GUI  Create a GUI that animates the rotation of a coordinate frame o Allow multiple rotations in sequence  Each could be about either about the x, y, or z axes o User should enter the angle for each rotation using sliders  Angle in degrees o Extra: Add a few standard UI controls  Zoom, … Slide 3 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Upon startup draw initial x, y, and z axes  Use code from lecture: Complex Numbers & 3D Plots3 o Mon, Nov 10  Start with a new empty GUI o Add the code from plot 3D to the beginning of the Opening function % --- Executes just before Rot_3D is made visible. function Rot_3D_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Rot_3D (see VARARGIN) -- Add your code here!!! Slide 4 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Test your initialization code before proceeding Next add sliders to control x, y, and z-axis rotation Slide 5 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Create the three sliders  Set slider property: o Tag: slider_thetaX o Min: 0.0 and Max: o Value: 0.0  Set slider property: o Tag: slider_thetaY o Min: 0.0 and Max: o Value: 0.0  Set slider property: o Tag: slider_thetaZ o Min: 0.0 and Max: o Value: 0.0 Slide 6 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers How can we update the lines and text using the slider angles?  Set the XData, Ydata, and Zdata properties of the lines and ‘Position’ of the text o Need handles to the objects!!  They must all be unique!!  Also store the current location of the x, y, and z-axes o Store in a matrix “R_mat” hlx = line([0 1], [0 0], [0 0],'Color','r', 'LineWidth', 3); htx = text(1.2, 0, 0, 'X','Color','r','FontSize',14); hly = line([0 0], [0 1], [0 0],'Color','g', 'LineWidth', 3); hty = text( 0, 1.2, 0,'Y','Color','g','FontSize',14); hlz = line([0 0], [0 0], [0 1],'Color','b', 'LineWidth', 3); htz = text(0, 0, 1.2,'Z','Color','b','FontSize',14); R_mat = eye(3,3);% The current x, y, and z axis vectors (cols) Slide 7 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers  We need to share those handles with the three callback functions  Add to the variable names “handles” structure in the Opening Function!! o Lets place all of those handles (and R_mat) into a single structure  Now add this structure to the “handles” data structure % Create a structure to contain all of our handles and R_mat my_plot = struct('lineX', hlx, 'lineY', hly, 'lineZ', hlz,... 'textX', htx, 'textY', hty, 'textZ', htz,... 'XYZ', R_mat); % Choose default command line output for Rot_3D handles.output = hObject; handles.my_3Dframe = my_plot; The “handles” data structure is available to all of the functions!!! Slide 8 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Now add code to each of the slider callback functions  For example the slider ThetaX o Use the rotate_x function from past homework assignment o “Pull-out” the x, y, and z axes for more readable code % Get the rotational angle and convert to rad theta = get(hObject, 'Value') * pi/180; % Update R_mat based on the requested rotation handles.my_3Dframe.XYZ = handles.my_3Dframe.XYZ*rotate_x(theta); % For ease of use define the current x, y, and z axes x = handles.my_3Dframe.XYZ(:,1); % Col 1 y = handles.my_3Dframe.XYZ(:,2); % Col 2 z = handles.my_3Dframe.XYZ(:,3); % Col 3 Use the debugger to test along the way!! Slide 9 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers  For example, for the slider ThetaX o Only need to rotate the y and z axes!! % Update the location of lines and text % Update y-axis (second col of R matrix) set(handles.my_3Dframe.lineY,'XData',... [0 y(1)], 'YData', [0 y(2)], 'ZData', [0 y(3)]); set(handles.my_3Dframe.textY,'Position', [1.2*y(1), 1.2*y(2), 1.2*y(3)]); % Update z-axis (third col of R matrix) set(handles.my_3Dframe.lineZ,'XData',... [0 z(1)], 'YData', [0 z(2)], 'ZData', [0 z(3)]); set(handles.my_3Dframe.textZ,'Position', [1.2*z(1), 1.2*z(2), 1.2*z(3)]); Test along the way!! Slide 10 of 13

Graphical User Interface Design in MATLAB Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Finally, we must update the “handles” to store our updated R_matrix Do the same for slider ThetaY and slider ThetaZ % Update handles structure guidata(hObject, handles); Test along the way!! Slide 11 of 13

Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers Want to apply change in  and not the absolute value of  for each slider!! persistent theta_k_1 if isempty(theta_k_1) theta_k_1 = 0.0; end % Get the rotational angle and convert to rad theta_k = get(hObject, 'Value') * pi/180; theta = theta_k - theta_k_1; theta_k_1 = theta_k; Slide 12 of 13 MATLAB code of our GUI

Next Lecture Monday 24 Nov 2014 EGR 115 Introduction to Computing for Engineers An open review  Work on our Battleship GUI? Slide 13 of 13