I cannot run an .m file containing script directly in command line
显示 更早的评论
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 个评论
Oleg Komarov
2011-4-25
Not enough info: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers
回答(2 个)
Walter Roberson
2011-4-26
If you are including the ".m" when you are invoking the script, then leave it off.
myscript.m %WRONG
should be
myscript %RIGHT
4 个评论
Matt Fig
2011-4-26
Did that really change between 2010a and 2011a?
Walter Roberson
2011-4-26
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
2011-4-26
In 2007b, I get:
??? Undefined variable "myscript" or class "myscript.m".
Jingyu
2011-4-26
Matt Fig
2011-4-26
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 个评论
Jingyu
2011-4-26
Matt Fig
2011-4-26
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?
类别
在 帮助中心 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!