The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Undefined function or variable - for no reason...
Replies: 1   Last Post: Feb 10, 2013 10:36 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Undefined function or variable - for no reason...
Posted: Feb 10, 2013 10:36 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Ben Lange" <> wrote in message
> I experienced this issue in the following scenario.
> Initially I named my .m file HW1.m, it worked fine.
> I then renamed my .m file to be HW1-NearestNeighboar.m.
> I experienced the dreaded Undefined function or variable error.
> I then changed the - to _ and everything worked fine.
> Apparenly, MatLab doesn't support - characters in the *.m filename.

That is correct.

"Valid function names follow the same rules as variable names. They must
start with a letter, and can contain letters, digits, or underscores."

If function names were allowed to contain a minus sign, this:


would be ambiguous -- it could be either a call to the function you wrote or
the result of subtracting the first element of the array NearestNeighboar
from the variable HW1.

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.