I cannot run an .m file containing script directly in command line
Show older comments
In version 2010a, I can do this very easily. I recently updated my Matlab to 2011a, and then I cannot do this any more. Do I have to change my script to matlab function file? How can I run it directly?
I use linux. Thanks!
1 Comment
Oleg Komarov
on 25 Apr 2011
Not enough info: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers
Answers (2)
Walter Roberson
on 26 Apr 2011
If you are including the ".m" when you are invoking the script, then leave it off.
myscript.m %WRONG
should be
myscript %RIGHT
4 Comments
Matt Fig
on 26 Apr 2011
Did that really change between 2010a and 2011a?
Walter Roberson
on 26 Apr 2011
In some of the earlier versions, the script would execute and then it would complain about not being able to access the field "m". Not so long ago (but I don't know which release) it was made a syntax error instead of an execution time error.
Matt Fig
on 26 Apr 2011
In 2007b, I get:
??? Undefined variable "myscript" or class "myscript.m".
Jingyu
on 26 Apr 2011
Matt Fig
on 26 Apr 2011
You don't say what happens when you try to run the script, but I suspect that the script is not in your new default directory for 2011a. Say your script is named myscript. At the command prompt do this (in 2011a):
which myscript % But use the name of your script of course...
If MATLAB returns:
'myscript' not found
then you need to put the file in the current directory. Once this is done, the script should work. The same goes for all your old files from 2010a.
The other option would be to simply set the current directory in 2011a to the directory which had your script...
2 Comments
Jingyu
on 26 Apr 2011
Matt Fig
on 26 Apr 2011
But is the name of your file 'myscript' or not? Walter and I used that as a generic name, you are supposed to use the real name of your file when trying to find it. Did you move the file to the current directory then use its name, not myscript (unless your file is actually named myscript), like I showed above?
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!