Matlab is an awesome thing for doing some heavy numerical computation and analysis. Though, Matlab is powerful in it's own right, it has wonderful support to run Java programs with-in the Matlab interface. Apparently, there is no easy way to call Matlab functions with-in Java and let Java read/print or use the output of those functions for some other purpose.
An article that seems to provide possible solution, calls for using a piece of code, MatlabControl class, that can be downloaded from here along with a patch that can be applied. The MatlabControl allows calling matlab functions with-in Java by creating a MatlabControl object and invoking the MatlabControl.blockingFeval function with arguments as function name and a list of arguments that the function takes. The output can be captured in a generic Object which can later be typecast depending on the expected output.
However, there is a major drawback with this. After setting the classpath in Matlab, a run of the corresponding Java code (invoking MatlabControl) in matlab makes the Matlab UI to hang and Matlab has to be restarted to do anything freshly. I figured out that it has to be invoked in a different thread so I tried the same but it hangs again.
In fact, if you are calling matlab functions at multiple places in your code or invoking MatlabControl with-in a for-loop or while loop and calling matlab functions for an indefinite number of times it never seems to work. Apparently, Mathworks provides the same kind of support to programs written in C or Fortran, much more easily. They only need to include the corresponding libraries and call the functions with the command to run. Hence, there is no easy way one can use the numerical computing power of matlab functions with-in the Java programs.
Recently, I came across another software from mathworks, Matlab Java Builder, that does some fancy stuff involving Java and Matlab. It converts the matlab programs in to Java classes that can be used stand alone with any other Java code without Matlab installed on the system. Perhaps, this might be helpful in using Matlab features with Java.
An article that seems to provide possible solution, calls for using a piece of code, MatlabControl class, that can be downloaded from here along with a patch that can be applied. The MatlabControl allows calling matlab functions with-in Java by creating a MatlabControl object and invoking the MatlabControl.blockingFeval function with arguments as function name and a list of arguments that the function takes. The output can be captured in a generic Object which can later be typecast depending on the expected output.
However, there is a major drawback with this. After setting the classpath in Matlab, a run of the corresponding Java code (invoking MatlabControl) in matlab makes the Matlab UI to hang and Matlab has to be restarted to do anything freshly. I figured out that it has to be invoked in a different thread so I tried the same but it hangs again.
In fact, if you are calling matlab functions at multiple places in your code or invoking MatlabControl with-in a for-loop or while loop and calling matlab functions for an indefinite number of times it never seems to work. Apparently, Mathworks provides the same kind of support to programs written in C or Fortran, much more easily. They only need to include the corresponding libraries and call the functions with the command to run. Hence, there is no easy way one can use the numerical computing power of matlab functions with-in the Java programs.
Recently, I came across another software from mathworks, Matlab Java Builder, that does some fancy stuff involving Java and Matlab. It converts the matlab programs in to Java classes that can be used stand alone with any other Java code without Matlab installed on the system. Perhaps, this might be helpful in using Matlab features with Java.
No comments:
Post a Comment