Matlab: Saving and Running M-files

  • Context: MATLAB 
  • Thread starter Thread starter teknodude
  • Start date Start date
  • Tags Tags
    Matlab Running
Click For Summary

Discussion Overview

The discussion revolves around issues related to saving and running M-files in MATLAB, specifically focusing on filename restrictions and behaviors in MATLAB R2006a. Participants explore the implications of using special characters in filenames and how these affect the ability to run the files.

Discussion Character

  • Technical explanation, Debate/contested, Conceptual clarification

Main Points Raised

  • One participant notes that MATLAB does not run M-files with filenames containing special characters like "#" and "." and mentions that simpler filenames work correctly.
  • Another participant suggests that M-file names must start with an alphabetic character and may contain alphanumeric characters or underscores, implying that certain characters are not allowed.
  • A participant reports that removing the "#" did not resolve the issue and that periods and hyphens also seem problematic based on testing with the isvarname function.
  • One participant describes a workaround involving manually adding ".m" to the filename, although they find this method inconvenient.
  • A later reply clarifies that the MATLAB dialog box appends ".m" automatically unless there are other periods in the filename, which may contribute to the confusion.

Areas of Agreement / Disagreement

Participants generally agree that certain special characters in filenames cause issues in MATLAB, but there is no consensus on the full extent of the restrictions or the best solutions to the problem.

Contextual Notes

Limitations include the lack of clarity on the complete set of valid characters for M-file names and the specific behaviors of MATLAB R2006a regarding filename handling.

teknodude
Messages
150
Reaction score
0
I've noticed a weird thing that Matlab does whenever I save my m-file then try to run it. If I save my M-file with a simple file name like "HW4" or "untitlited" it will run. However if i save my m-file as file name HW#4_3.40 (I just wanted to label the file with the problem # from the text I'm using), the option for run is not highlighted and it doesn't work if I do command run HW#4_3.40. I also made sure that the target directory is correct. When I check the folder I saved the m-file file name HW#4_3.40 is detected by windows as an unknown file, while other files with simple names is detected as m-file.

I searched a little to maybe find out if this is a bug or something. I'm somewhat new to MATLAB so I'm not sure if there are some restrictions to filenames for m-files. Also I am using Matlab R2006a.
 
Physics news on Phys.org
Try taking out the hashes from the filename.
M-file names must start with an alphabetic character, may contain any alphanumeric characters or underscores[...]

http://www.caspur.it/risorse/softappl/doc/matlab_help/techdoc/matlab_prog/ch8_pr15.html
 
Last edited by a moderator:
Thanks for the link. I tried taking out the #, but it didn't work. I played around with isvarname to test the file names. Guess it doesn't like periods or even hyphens. I did find a way around this by going to the folder the file is saved in and adding a ".m" to the end of the filename, but that's somewhat annoying to keep doing.
 
When you enter the file's name to be saved, the dialog box will automatically append .m, but only if there are no other periods already in the file name.

- Warren
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K