
It consists of a single MATLAB expression and any number of input and output arguments. This function calculates the maximum of theĪn anonymous function is like an inline function in traditional programming languages, defined within a single MATLAB statement. MATLAB will execute the above statement and return the following result − The comment lines that come right after the function statement provide the help text. In our example, the mymax function has five input arguments and one output argument. It gives the name of the function and order of arguments. The first line of a function starts with the keyword function.

%This function calculates the maximum of the It takes five numbers as argument and returns the maximum of the numbers.Ĭreate a function file, named mymax.m and type the following code in it −


The following function named mymax should be written in a file named mymax.m. The name of the file and of the function should be the same.įunctions operate on variables within their own workspace, which is also called the local workspace, separate from the workspace you access at the MATLAB command prompt which is called the base workspace.įunctions can accept more than one input arguments and may return more than one output arguments.įunction = myfun(in1,in2,in3. In MATLAB, functions are defined in separate files. A function is a group of statements that together perform a task.
