IN-LINE VS. ANONYMOUS FUNCTION
- Adisorn O.
- Mar 9, 2023
- 1 min read
Updated: Mar 19, 2023
Sometimes we must define a short function for using with our main program or inside the user function. The in-line function is made for this purpose. It is easy to define a single return value function without creating an m-file. The syntax of the in-line function is in the form.
f = inline('expression', 'p1', 'p2',...)
An anonymous function is an advanced form of an in-line function. It requires no use of quotation marks for the expression and input arguments.
f = @(p1,p2,...) expression
Just specify f(p1,p2,...) to call the function.
Both in-line and anonymous functions can return only a single value. We cannot call for other functions inside them.