Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)

Slides:



Advertisements
Similar presentations
Tutorial on Matlab and OpenCV Rui Ma TA of CMPT 414 May 14, 2013 Office hours: Fridays 11:00-12:00, CSIL TA Office 1 (ASB 9838)
Advertisements

Introduction to MATLAB The language of Technical Computing.
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Introduction to Matlab
Matrix Manipulation and 2D Plotting
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Lecture 4.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 20P. 1Winter Quarter Propulsion Lab with MATLAB Lecture 20.
Maths for Computer Graphics
Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Programming in MATLAB Week 14 – 4/28/09 Kate Musgrave
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Matlab Basics IEF 217a: Lecture 2 Fall 2002 Sigmon and Davis, chapters 1-7.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
Matlab tutorial course Lesson 2: Arrays and data types
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
INTRODUCTION TO MATLAB LAB# 01
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
Post-Processing Output with MATLAB Claudia Fricke Institute of Petroleum Engineering, Heriot Watt University.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 9”
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Beginning Programming for Engineers Introduction to Programming and Computer Science.
Outline Announcements –Homework I due Wed. 5PM by Subject: CIS 402 Homework 1 Plain text Not allowed to use errorbar Try to do plotCI without looking.
4.4 Identify and Inverse Matrices Algebra 2. Learning Target I can find and use inverse matrix.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Figures & Axes, Printing & Saving. Outline Announcements –Homework I due Wed. 5PM by –No lecture on Fri. 10/26, rescheduled to Wed. 10/31 at 8AM.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
Introduction to Matlab Module #8 Page 1 Introduction to Matlab Module #8 – Animation Topics 1.getframe 2.pause 3.Plotting a set of files Textbook Reading.
EGR 115 Introduction to Computing for Engineers Graphical User Interface Design in MATLAB - Part 2 Monday 24 Nov 2014 EGR 115 Introduction to Computing.
Spring 2016 Statics - TAM 210 & TAM 211 Discussion 1 - Intro to Matlab 1.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 20P. 1Winter Quarter Propulsion Lab with.
Handling Arrays 1/2 Numerical Computing with. MATLAB for Scientists and Engineers.
Using and Programming with MATLAB as an Engineering Tool [ Part III ]
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
การใช้งานโปรแกรม MATLAB ดร. อำนาจ ขาวเน. BASIC ELEMENTS OF MATLAB MATLAB Desktop MATLAB Editor Help System MATLAB (MATrix LABoratory)
Machine Learning Octave tutorial 데이터 마이닝 박 영 택.
An Introduction to Programming in Matlab Emily Blumenthal
EEE 242 Computer Tools for Electrical Engineering
Beginning Programming for Engineers Introduction to Programming and Computer Science.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
Reading and Writing Image Files
Ch3 Graphics Overview of Plotting Editing Plots
Part I – Matlab Basics.
Matlab tutorial course
Communication and Coding Theory Lab(CS491)
Introduction to MATLAB
MATLAB stands for MATrix LABoratory.
Presentation transcript:

Beginning Programming for Engineers Animation

Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4) The ones function creates a matrix with all elements set to 1. The zeros function creates a matrix with all elements set to 0. The eye function creates an identity matrix. The magic function creates a magic square.

Using end as a subscript Try these commands: >> clear >> B = (1:100).^2; >> B(end) >> A = [1 2 3; 4 5 6]; >> A(end,2) >> A(1,end) >> A(end,end) >> A(end) >> A(1,end) = 99; >> A Using a subscript of end means choose the last row of the column, or last column of the row... This use of end can be on the receiving side of an assignment, too.

Slicing matrices: Vectors of subscripts Try these commands: >> M = magic(7) >> M([1 3 6], 4) >> M([1 3 6], [2 5]) >> M([1 end],[2 end]) >> M([1 end],[2 end]) = 0; >> M We can choose several elements of a row or column by giving a vector as a subscript. We can use vectors for both rows and columns to collect a matrix. We can sensibly use end in these vector subscripts.

Slicing matrices: Subscript ranges >> M = magic(5) >> M(2,1:2:end) >> M(:,2) >> M(2,1:2:end) =... [ ] >> M(4,3:end) = 0 We can use ranges as subscripts. The end keyword can be sensibly used. Using plain : as a range selects the entire row or column.

Saving variables to a file save 'filename' Saves all variables in the workspace to filename.mat save 'filename' x y z Saves the variable x, y, and z to filename.mat whos Lists all the variables in the current workspace. whos -file 'filename' Lists all the variables save in filename.mat

Loading variables from a file load 'filename' Load all the variables stored in filename.mat into the workspace. Variables not stored in filename.mat are unchanged. load 'filename' x y z Load the variables x, y, and z from filename.mat into the workspace.

Changing how numbers are printed help format format compact format bank magic(4)

Graphics handles on subplots Figures and subplots can return a "handle" to allow objects to be added later. clear; clc % Set up subplots figure('Color', 'white'); s1 = subplot(1,2,1); hold on; s2 = subplot(1,2,2); hold on ; % First objects in subplots. plot(s1, cosd(0:360), sind(0:360)); plot(s2, 0:5, (0:5).^2); % Second objects in subplots plot(s1, 0.5*cosd(0:360), 0.5*sind(0:360)); plot(s2, 0:5, (0:5).^3);

Graphics handles on figures Use gca to get the "axes" object handle. clear; clc % Set up figures figure; hold on; f1 = gca; figure; hold on; f2 = gca; % First objects in figures. plot(f1, cosd(0:360), sind(0:360)); plot(f2, 0:5, (0:5).^2); % Second objects in figures plot(f1, 0.5*cosd(0:360), 0.5*sind(0:360)); plot(f2, 0:5, (0:5).^3);

Graphics handles on plot objects The plot function can return a handle that may be used to see and modify properties of the line. ph = plot([1 5],[1 5], 'r', 'LineWidth', 3); The get function can get some or all properties. get(ph) get(ph, 'LineWidth') The set function changes properties set(ph, 'LineWidth', 5);

The XData and YData properties In a plot object, the XData and YData properties are the coordinates of the plotted data itself. ph = plot([ ], [ ]); get(ph, 'XData') Changing the values of XData, YData, and other properties changes the drawn object! set(ph, 'XData', [ ],... 'YData', [ ]); set(ph, 'Marker', 'o');

pause and drawnow Since drawing takes time, Matlab batches up graphics commands. Result: You only see the final result! To get animation, we need to tell Matlab to draw what it has before continuing. drawnow Alternatively, tell Matlab to draw, and pause. This is useful if the animation is running too fast. pause(0.15) % Draw, and pause 0.15 seconds Use movie and getframe to build "movies".

Polygon operations The fill function is like plot except it creates a filled polygon. fill([1 2 3], [0 3 2], 'r'); The polyarea function computes the area of a polygon. polyarea([1 2 3], [0 3 2]) The inpolygon function tests if a point is in a polygon or not. inpolygon(3,3, [1 2 3], [0 3 2])