week8_lec1-2_userdefined_s09

# week8_lec1-2_userdefined_s09 - Announcements CANCELLED THIS...

This preview shows pages 1–11. Sign up to view the full content.

Announcements CANCELLED THIS WEEK: Prof. Diefes-Dux Office Hours Regularly: Wed 9:30-11 am, ARMS B098 Exam 2 Tuesday March 10, 6:30-7:30 PM ELLT 116 All students with exam conflicts or needing accommodations MUST see Chell Nyquist ( [email protected] ) Upcoming Postings on Blackboard: Learning Objectives Past Exams and Solutions Assigned Seating for the exam

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
User-Defined Functions Learning Objectives At the end of this class period, you will begin to be able to: Explain what a user-defined function is in MATLAB Describe at least two reasons why we create user- defined functions in MATLAB Identify at least three essential elements of a user defined function in MATLAB Describe how to pass variables to and from a user- defined function MATLAB Notes pp. 93-95
Functions Below is a simple view of the overall function of a washing machine The box, representing the function, has inputs, outputs, and “stuff that goes on inside the box” WASH Dirty clothes Clean clothes

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Functions in MATLAB MATLAB functions are similar in that they have: Input Arguments – these are variables (scalars, vectors, matrices, character strings…) Outputs Arguments – these are variables (scalars, vectors, matrices, character strings…) Operations on the Input Arguments Approximate Taylor series Angle Sine of angle Function Operates on Input(s) Input(s) Output(s)
Functions in MATLAB The format of a function requires that we keep track of input arguments, output arguments, and the function code itself (the stuff in the box) >> x = [3 5 7 9 10] >> y = mean(x) Approximate Taylor series Angle Sine of angle mean function set of data mean value of data input output

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Functions in MATLAB Take a look at a function in MATLAB’s toolbox >> type mean function y = mean(x,dim) %MEAN Average or mean value. % …Help lines… if nargin==1, % Determine which dimension SUM will use dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end y = sum(x)/size(x,dim); else y = sum(x,dim)/size(x,dim); end Note: You cannot access the code for built-in functions
Characteristics of MATLAB Functions What happens in a function stays in the function >> x = [5 6; 7 3; -1 10; 1 1] >> mean(x) >> who How a function acts is affected by inputs Example 1: Multiple actions of mean function >> mean(x,1) >> mean(x,2) Example 2: Multiple actions of plot function

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Functions in MATLAB What about when there is no “built-in” function available? Example: Say we want a function that computes the circumference of a circle. …Need user-defined functions ??? radius ??? ???
Functions in MATLAB Why would I want to create a function in MATLAB? (Team Activity: 1 min) - -

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
How does this relate to user-centered design? Everything we just said relates to make MATLAB more
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/06/2011 for the course ENGR 126 taught by Professor Oakes during the Spring '08 term at Purdue.

### Page1 / 32

week8_lec1-2_userdefined_s09 - Announcements CANCELLED THIS...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online