in reply to interacting with background shell

It might be worth looking into MATLAB's features. I know some other similar programs (eg, IDL), have a server mode, so that that you can start up and instance, and send commands to it.

I found mention of a 'MATLAB server', but I have no idea if it requires a different license from the standard MATLAB.

You might also be interested in Math::Matlab.