开发者

Run a MATLAB script from Windows DOS prompt

开发者 https://www.devze.com 2023-04-10 09:00 出处:网络
I am trying to run a Matlab script from Windows command prompt but I can\'t execute it sometimes.The scr开发者_开发百科ipt runs fine when manually launched.Matlab version is 2011a and Windows is Serve

I am trying to run a Matlab script from Windows command prompt but I can't execute it sometimes. The scr开发者_开发百科ipt runs fine when manually launched. Matlab version is 2011a and Windows is Server 2003 SP2. Details:

Script mytask.m is located inside say E:\Production\Project. This is SAVED on Matlab's path.

When I place mytask.m inside bin folder, it executes fine by the command:

     `C:\Program Files\MATLAB\R2011a\bin>matlab -r mytask`

If you delete it and try to access it at its original location, the script doesn't run although Matlab editor window is launched:

     `C:\Program Files\MATLAB\R2011a\bin>matlab -r "E:\Production\Project\mytask"

Any suggestions please? Thanks.


The syntax for matlab -r is

matlab -r "statement"

In other words, you need to provide some executable commands as the statement. For example:

matlab -r "run E:\Production\Project\mytask"

However, it seems that matlab does not load the customized paths in this way. If you have some customized paths, you probably have to define them in startup.m and place this startup.m in the directory where you invoke matlab.

I didn't check myself, but if you define E:\Production\Project\ as the path in startup.m, you probably can run matlab -r mytask without problem, as mytask will be recognized as a user function/script.

A simple example of startup.m

path(path, 'E:\Production\Project\');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号