Running java code as a function in Matlab

I am interested in using some of the algorithmic trading code written by the Matlab community (Some examples are in this link: http://www.mathworks.com/matlabcentral/fileexchange/?term=trading ) and working on my own. Most online market APIs provide sample code written in Java, but I am having some issues getting Java code to work in Matlab in the ways I want it to. I want to use Java code like a Matlab function. Ultimately I want to be able to issue buy and sell commands to BTCChina through Matlab. Sample code for doing this with Java can be found here: https://github.com/BTCChina/btcchina-fix-api-java . I tried the build a mex-function technique (found here: http://www.mathworks.com/help/matlab/ref/mex.html#bt2l4qg-3 ) but I can only find documentation for C/C++ or Fortran. If anyone could give me some advice, or point me in the right direction, or if anyone has worked through something similar before, I would really appreciate it.

Answers (1)

You can call java code directly from matlab. No need to go through mex (which is indeed only for C/C++ or Fortran).
An example (using java class BigInteger):
bigi = java.math.BigInteger('1234567890123456789')
bigp = bigi.nextProbablePrime
r = double(bigp.remainder(java.math.BigInteger(100)))

Asked:

on 6 Jan 2015

Answered:

on 6 Jan 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!