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
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
Walter Roberson 2011 年 4 月 26 日

0 投票

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
Matt Fig 2011 年 4 月 26 日
Did that really change between 2010a and 2011a?
Walter Roberson
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
Matt Fig 2011 年 4 月 26 日
In 2007b, I get:
??? Undefined variable "myscript" or class "myscript.m".
Jingyu
Jingyu 2011 年 4 月 26 日
the message I got is:
Undefined variable "muscript" or function "myscript.m"
the .m file is not a function, just script.

サインインしてコメントする。

Matt Fig
Matt Fig 2011 年 4 月 26 日

0 投票

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
Jingyu 2011 年 4 月 26 日
I put the file in the current directory. However, I got the following message:
Undefined variable "myscript" or function "myscript.m"
Matt Fig
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 ExchangeFile Operations についてさらに検索

タグ

質問済み:

2011 年 4 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by