MATLAB: How to execute an .m file from the command line in windows without opening a new matlab copy

batchcommandlineMATLABwindows

The problem is, I want to execute a certain .m file from the command line. I know how to do already:
matlab -nosplash -r "run whathever.m"
Problem is, this opens a new instance of Matlab, I don't want that, I want it to simply use the already open instance of Matlab. Is there any way of doing that?

Best Answer

I think you need to write code to call into MATLAB as a COM Server. You will also need to ensure that your currently running MATLAB session has been enabled to run as a COM Server. The instructions here should help with that.