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?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • 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. – linguanerd Jul 13 '13 at 15:55

1 Answers1

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.

s.bandara
  • 5,636
  • 1
  • 21
  • 36