Lecture 8

# Lecture 8 - 11/1/2010 Lecture 8: User-defined functions...

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

11/1/2010 1 Lecture 8: User-defined functions (continued) BMEn 2401 Programming for Biomedical Engineers Rich Beck November 2, 2010 1 Today’s lecture Review of User-defined function Using functions in one file Recursive functions 2

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

View Full Document
11/1/2010 2 Review: Functions % Script grade_vec = [10 10 7 8 10 9]; my_median1 = median(grade_vec) 1. MATLAB calls function (ex. median ) 2. Values of input variable(s) passed to function (ex. x = [10 10 7 8 10 9] , dim = [] ) 3. Algorithm in function uses input(s) to determine output(s) (ex. x b y ) 4. Values of output variable(s) passed to function (ex. y = 9.5 ) To view median.m, in MATLAB editor, Open b C:\Program Files\MATLAB\R2009b\toolbox\matlab\datafun\median.m 3 function y = median(x,dim) MATLAB Built-in Function median Review: Functions % Script grade_vec = [10 10 7 8 10 9]; tot_grade1 = MySum(grade_vec) NOTES: Variables used in the function call do not need the same variable names as variables in the function (true of both built-in & user-defined functions). This example: grade_vec and V different variable names, same values. However, the variable names in the first line of the function (function declaration line) must be used within the function . This example: input V used to calculate the output variable sum . 4 function sum=MySum(V) sum=0; for i=1:length(V) sum=sum+V(i); end Function MySum from HW 6
11/1/2010 3 Multiple Inputs/Outputs The order of variables in the function call and the function declaration line

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/10/2011 for the course BMEN 2051 taught by Professor S during the Fall '10 term at Minnesota.

### Page1 / 11

Lecture 8 - 11/1/2010 Lecture 8: User-defined functions...

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

View Full Document
Ask a homework question - tutors are online