Function inside script in Matlab?
10,207
This is correct, MATLAB does not allow you to define full function
s in a script. However, there are at least two solutions that may help you:
You could turn the script into a function. Workspace variables you are referring to from within your scripts would become arguments of the function, and you could return certain result variables.
If your helper function is really small, you may be able to define it in your script as an anonymous functions without the
function
keyword, as inpoly = @(x) x.^2 + 3 * x - 4;
- a polynomial function, for example.
Related videos on Youtube
Comments
-
Suzan Cioc over 1 year
Can I have fast and short helper local function to use inside script?
Currently I have "FUNCTION keyword use is invalid here" message.
Why?