Archived

This forum has been archived. Please start a new discussion on GitHub.

Interfacing to Matlab using Ice

Hello everyone.

I am looking for recommendations on interfacing to Matlab through Ice. Essentially, I'd like to be able to execute a matlab script (that conforms to a slice definition) remotely and through another language like Java.

Right now I am able to do this by using a combination of Matlab, Matlab objects, MatlabControl, and Java. (Note: MatlabControl is a utility that allows Matlab function calls from Java).

Here is how I did it so far:
  • In Matlab I created a Matlab object called "simplescript". It contains a function "test()" that just displays a message like "Hello World"
  • In Java I generated Ice stub code from a "MatlabIceScript" slice file that just has a single interface "ScriptIce" with one function "test()". I implement the test() function with MatlabControl function call: "LocalMatlabProxy.eval(var + ".test()");" where "var" is the Matlab script name. I compile this into a jar called MatlabIceScript.jar
  • In Matlab I created a script that acts as an Ice Server. It instantiates a simplescript object, named "scriptObj". It then instantiates a MatlabIceScript object, with "scriptObj" as the "var" value from above. I then initialize ice, create an adapter, add the MatlabIceScript object to the adapter labeled "SimpleScript", etc.
  • In Java, I created a file that acts as an Ice Client. It simply creates an Ice proxy to "Simple Script", casts to an objectcalled "script", and calls script.test().

So in summary I have:
  1. Ice Client in Java to call the matlab function
  2. Ice Server in Matlab that instantiates Ice object and waits for calls
  3. Ice object code, generated in Java, but used in Matlab (from MatlabIceScript slice file)
  4. Matlab object that implements "test()" on matlab's end so a remote client can call it.

This all works well, but I felt there were a lot of steps that may be unnecessary (particularly the use of MatlabControl?) Anyone have any recommendations on how this can be slimmed down so a remote client of a different language can call arbitrary Matlab scripts that conform to the slice methods?

Also, if the description is too confusion, I can upload the code if that is easier.

Thank you!