{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Exam 3 Review

# Functions matlab functions can accept and return

This preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: functions can accept and return different numbers of arguments. This is handled by using the values nargin and nargout. nargout. nargin/nargout nargin is equal to the number of input arguments passed into the function. nargout is equal to the number of output arguments requested from the function. Function Handles Create a function handle by prepending @ before a function name. For example, suppose we have defined: function y = myfunc(x) y = x^3 + x 3; Then @myfunc is a function handle, and feval( myfunc, expr) feval(@myfunc, expr) behaves just like myfunc(expr) myfunc(expr) If we assign myf2 = @myfunc , then myf2(expr) also @myfunc myf2(expr) behaves just like myfunc(expr) myfunc(expr) 8 Anonymous Functions name = @ (argumentList) expression (argumentList) name: name: the name of the function argumentList: argumentList: a list of one, or many, independent variable(s) passed in as arguments separated by commas expression: expression: a single, valid mathematical MATLAB expression written according to the dimensions of the arguments Outline Lecture 15 and 16 Intro to MATLAB and Matrices Lecture 17 Script and Function Files Lecture 18 and 19 MATLAB Programming Lecture 20 Subarrays and Vectorization Lecture 21 Plotting in MATLAB Using Subarrays You can use pieces of arrays just as you would arrays. For example if you have an arr...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online