The third type of function that we will learn about are anonymous functions. Unlike internal and external functions, anonymous functions can be defined anywhere in your script file. (As long as they are defined before their function callback!) Let's take a look at how they work.
matlab
f = @(x) x + 2;
f(3); % output: 5
So, in terms of defining the anonymous function, we follow this format: handle = @(inputs) action.
In the above example, our handle was 'f', which was then used to call the anonymous function later in the script. As for the inputs, those must be wrapped inside of parenthesis and must follow an '@' symbol. This tells MATLAB what is being passed into the function. After that, we specify what we would like the function to do and voila, that's it!
In the example above, we only had one input to the anonymous function, but what if we had multiple inputs? Let's check it out.
matlab
g = @(x, y) x*y;
g(2,3); % output: 6
If an anonymous function needs more than one input, simply add a comma in between each input and then you're set!