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 Comment

Not enough info: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers

Sign in to comment.

Answers (2)

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

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

Sign in to comment.

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

I put the file in the current directory. However, I got the following message:
Undefined variable "myscript" or function "myscript.m"
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?

Sign in to comment.

Categories

Tags

Asked:

on 25 Apr 2011

Community Treasure Hunt

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

Start Hunting!