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에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!