How to run MATLAB files in batch mode (or as a batch process). Guide request.
조회 수: 179 (최근 30일)
이전 댓글 표시
Hello, my problem can likely be resolved with a simple guide. Unfortunately I simply haven't been able to find one. I've only used MATLAB in interactive mode and have no experience with running anything in batch mode or as a batch proccess. So that said, could someone point me to a guide (or two, reading more never hurts) that could walk me through the steps I need to take?
댓글 수: 0
답변 (4개)
Walter Roberson
2012년 6월 20일
matlab -r "statement"
The statement should be the bit of MATLAB code you want to execute.
I recommend
matlab -noFigureWindows -r "try; run('C:\Path\To\YourScriptName.m'); catch; end; quit"
To be safe, YourScriptName.m should have instructions to cd() to the directory it is to work in.
run() cannot be used with functions, only with scripts. For functions,
matlab -noFigureWindows -r "try; cd('C:\Path\To\'); YourFunctionName(); catch; end; quit"
The above commands could be put into a .bat file, and could be invoked from any directory (because the mini-script changes directory.)
per isakson
2012년 6월 19일
The name of the guide is the online documentation. It includes many examples and demos. Your question puzzles me
- what do you understand with "batch"?
- do you know "function" and "script" in Matlab?
Search for "Programming Fundamentals" and "Working with Functions in Files" in the online documentation.
See: Demos | Getting Started | Writing a MATLAB Program (5 min, 45 sec)
If you want to invoke Matlab from a "dos batch file" see:
Start MATLAB program (Windows platforms)
Syntax
matlab helpOption
matlab -automation
....
댓글 수: 2
Walter Roberson
2012년 6월 19일
"batch" can also refer to a mode for use with distributed computing.
Be sure to see the -r switch (or is it /r on Windows?) to indicate which .m file to begin.
Ricky
2012년 6월 20일
hey Alfonso,
I'm not sure if this what you're after. Read the first part of it (don't worry about the grid part)
댓글 수: 0
MHS
2018년 5월 18일
Hi Everyone ! I have several .m files which take a lot of time to execute, I intend to execute sequentially those .m files while saving the workspace variables for each m-file. Do I need to write a batch file to do this while I am away and I can run the batch file which calls the m-files sequentially. Can anyone guide me how to do that for simple m-files . Will appreciate any help in this regard Maqsood
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!