Functions matlab functions can accept and return

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

View Full Document Right Arrow Icon
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

This note was uploaded on 05/04/2010 for the course ENGIN 101 taught by Professor Jeffringenberg during the Spring '07 term at University of Michigan.

Ask a homework question - tutors are online