Different behaviour while running Matlab script from DOS window
Show older comments
Hi,
I have a problem starting Matlab from DOS window for different versions of Matlab.
When I call Matlab 2010bSp1 (32 bit) from DOS window to run a script, I do not see any problem.
C:\ProgramFiles\matlab\r2010bsp1\bin\matlab.exe -r "add.m"
When I call Matlab 2014a (64 bit) from DOS window to run the same script, I see a problem
C:\ProgramFiles\matlab\r2014a\bin\matlab.exe -r "add.m"
The MATLAB command window shows Undefined variable "add" or function "add.m".
Note that the path of "add.m" is not added to search path of Matlab in either case.
Can anyone please let me know why MATLAB r2014a version is not able to identify "add.m"?
Any help is highly appreciated.
1 Comment
Walter Roberson
on 18 Sep 2016
Note: there is an R2010bSp2 that you are entitled to if you have R2010bSp1 .
Accepted Answer
More Answers (1)
Jan
on 16 Sep 2016
0 votes
If add.m is not added to the Matlab path, it should not work in R2010. Why does this Matlab version find the function? Is it in the userpath or in the current path?
If you want Matlab 2014a to find the function, adding it to the Matlab path is obligatory.
4 Comments
Nagaraj
on 17 Sep 2016
Jan
on 17 Sep 2016
The workaround is clear: Add the folder to the path, e.g. by addpath or add it in the calling sequence in the command line.
By the way: The command shoulöd not be called "add.m", but "add", because ".m" does not belong to the Matlab command.
Nagaraj Ramachandra
on 19 Sep 2016
The issue mentioned by me is regarding running M-script from Windows Command Prompt.
In my case, I cannot add the script folder to MATLAB's search path. I have lots of M-scripts(which are in different locations) which I want to run from Windows command prompt.
I have created a service request and Mathworks engineer is looking into the issue.
Jan
on 20 Sep 2016
You can add the path easily when Matlab is called from the command line:
matlab -r "addpath('C:\Your\Path'); add"
or if add.m is a script and not a function file:
matlab -r "run('C:\Your\Path\add')"
Categories
Find more on Startup and Shutdown 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!