MATLAB: Is there a way to use a “.bat” file to call a MATLAB script from a MATLAB command line without the bat file opening up a new MATLAB session

bat filesdos

I have a MATLAB session already opened. I would type the following from the command line: dos('temp.bat'). This would result in the opening up of a new MATLAB session within which the results are generated and outputted. I am trying to prevent this new MATLAB session from opening up. I would prefer if the results generated by the MATLAB script would be outputted within the same MATLAB session from which the "dos" command was used.
The current syntax of 'temp.bat' is as follows: "matlab.exe" -r "filename"
Thanks
Floyd

Best Answer

"matlab.exe" -nodisplay -r "filename"
This will cause MATLAB to output to standard output, which will be read by your dos() command when the invoked MATLAB session finally finishes.
By the way, your -r should not be filename, it should be a command -- which could be the name of a script or the name of a function that you have stored in a file. Just don't put the .m in the -r string.