如何cmd命令行下直接运行Matlab的M文件

如何cmd命令行下直接运行Matlab的M文件

在系统变量中加入matlab的路径

win10下右键此电脑-属性-高级系统设置-环境变量-系统变量-编辑path 加入:

D:\MATLAB\R2013a\bin\win64(根据自己的来)。

此时重新打开cmd 键入matlab就能直接通过命令行启动matlab,不过导师的要求是直接在cmd中直接启动m文件,于是查看了matlab的启动参数。

matlab的启动参数

echo     -nosplash            - Do not display the splash screen during startup.
echo     -nodesktop           - Do not start the MATLAB desktop. Use V5 MATLAB
echo                            command window for commands. The Java virtual
echo                            machine will be started.
echo     -nojvm               - Shut off all Java support by not starting the
echo                            Java virtual machine. In particular the MATLAB
echo                            desktop will not be started.
echo     -memmgr manager      - Set MATLAB_MEM_MGR to manager.
echo                            manager - cache  (default)
echo                                    - fast   for large models or MATLAB code
echo                                             that uses many structure or
echo                                             object variables. Is not helpful
echo                                             for large arrays.
echo                                    - debug  does memory integrity checking.
echo                                             Useful for debugging memory
echo                                             problems caused by user mex
echo                                             files.
echo     -check_malloc        - same as '-memmgr debug'.
echo     -r MATLAB_command    - Start MATLAB and execute the MATLAB_command.
echo                            Any "M" file must be on the MATLAB path.
echo     -logfile log         - Make a copy of any output to the command window
echo                            in file log. This includes all crash reports.
echo     -timing              - Print a summary of startup time to the command
echo                            window. It is also recorded in a timing log,
echo                            the name of which is printed to the MATLAB
echo                            command window.
echo     -noFigureWindows     - Never display a figure window
echo     -automation          - Start MATLAB as an automation server,
echo                            minimized and without the MATLAB splash screen.
echo     -regserver           - Register MATLAB as a COM server
echo     -unregserver         - Remove MATLAB COM server registry entries.

根据上面意思,若想最小界面运行m文件,只要在cmd中键入:

matlab -nosplash -nodesktop -r yourmfile

(注意不加.m)。如果运行的m文件需要输入参数可以参考这一条输出:

这里写图片描述

字符串加单引号,有输入的时候必须加双引号。
这种方式在cmd运行m文件之后一定会出现这个窗口,所以并不能完全脱离matlab界面,但是由于能满足工程要求,因此到这步就足够了。

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_16019107/article/details/77882017