3

Can I have fast and short helper local function to use inside script?

Currently I have "FUNCTION keyword use is invalid here" message.

Why?

1
  • If you post a short snippet of code, you are more likely to get a response. You did not provide much information to work with. Commented Jul 13, 2013 at 15:55

1 Answer 1

5

This is correct, MATLAB does not allow you to define full functions in a script. However, there are at least two solutions that may help you:

  1. 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.

  2. 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 in poly = @(x) x.^2 + 3 * x - 4; - a polynomial function, for example.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.