Note To avoid confusion, use the same name for both the function file and the first function within the file.
Be sure to give the function a comment block explaining its use. For more information on section breaks and running live scripts, see Run Sections in Live Scripts.
Remember to save your m-files in the current directory. However, instead of manually updating the script each time, you can make your program more flexible by converting it to a function.
For this reason, you cannot add section breaks within local functions in live scripts. The first line of every function is the definition statement, which includes the following elements.
Examples collapse all Function with One Output Define a function in a file named average. Script files cannot have the same name as a function in the file.
Local functions, similar to other functions, have their own workspaces that are separate from the base workspace. Functions are supported in scripts in Rb or later. The local functions mymean and mymedian calculate the average and median of the input list and return the results.
That is, when you call a function within a program file, MATLAB checks whether the function is a local function before looking for other functions. To edit or delete an existing run command, select the command, right-click, and then select Edit or Delete.