Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB Runs Filename

  1. Apr 26, 2010 #1
    I'm having a weird problem in my copy of MATLAB at work ( Release 13 SP1). Originally I was having a problem with naming a file "any.m" as it wouldn't run. So I named it anyd.m and no problem afterward and I just assumed that word was some sort of script or something already defined in the program. Well now here's the kicker. I need to put a date in my filename now and I can't or can (really weirdly) get the files to run. Here's a few examples of filenames and what happens when they run.

    4 1 2008.m
    FAC 4 1 2008.m
    (that's the really weird one)

    File runs and displays my plot as it should

    What's causing this? I have no problems naming files whatever I please on my home computer, though it is running a newer version than here at work.
    Last edited: Apr 26, 2010
  2. jcsd
  3. Apr 26, 2010 #2
    Matlab m-files need to have names that are valid variable names. When you run your script, Matlab behaves as if you simply entered the name of the file into the command line. That's why the filename 4-2001-2008 gave -2005. It interpreted the dashes as minus signs. You can use the function isvarname to check to see if a string is a valid variable name.
  4. Apr 27, 2010 #3
    OK thank you, I'll have to devise a new naming scheme for the files I need to create, and isvarname should come in handy thank you.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook