MATLAB Solving Filename Issues in MATLAB 6.5.1

  • Thread starter Thread starter darkfall13
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
MATLAB 6.5.1 has specific rules for naming files, as filenames must adhere to valid variable name conventions. The user encountered issues when attempting to name files with spaces or special characters, resulting in errors or unexpected outputs. For example, naming a file "4-1-2008.m" caused MATLAB to interpret the dashes as minus signs, leading to incorrect results. The function isvarname can be used to verify if a filename is valid. A new naming scheme is necessary to avoid these issues in the future.
darkfall13
Messages
30
Reaction score
0
I'm having a weird problem in my copy of MATLAB at work (6.5.1.199709 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
? 4 1 2008
|
Error: Missing operator, comma, or semicolon.

FAC 4 1 2008.m
? FAC 4 1 2008
|
Error: Missing operator, comma, or semicolon.

4-1-2008.m
ans =

-2005
(that's the really weird one)

test1m.m
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:
Physics news on Phys.org
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.
 
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.
 

Similar threads

Replies
4
Views
1K
Replies
18
Views
6K
Replies
5
Views
2K
Replies
4
Views
1K
Replies
3
Views
2K
Back
Top