ABSTRACT

This chapter covers the self-written function, which is the last of the building blocks that we mentioned earlier. Self-written functions are equivalent to subroutines in most programming languages, but in MATLAB they are usually stored in separate files instead of the main program. This MATLAB function requires the user to write a self-written function, either as a separate.m file or as an anonymous function within the main script. MATLAB has a template for writing a function, which can be accessed by clicking on the down arrow under new in the toolstrip in the Editor Window and selecting function from the dropdown menu. Sometimes it is more convenient to define a function inside your script rather than in a separate file. There are times when we might be interested in determining a relative minimum of a single variable function. MATLAB has a built-in function that will do this for us.