Note: this project is effectively in hibernation as its author no longer has access to matlab.
Prerequisites
mexjulia requires MATLAB (tested with R2016b) and Julia (>=v.0.6-dev) along with a C++ compiler configured to work with MATLAB's mex command, the last is required for building the mexjulia MEX function. You can check that a compiler is properly configured by executing:
>> mex -setup C++
from the MATLAB command prompt.
Configuration
Start MATLAB and navigate to the mexjulia directory. Once there, run:
>> jl.config
You will be prompted to select a julia executable. The build process will:
use julia to determine build options,
build the mexjulia MEX function from source,
add the mexjulia directory to your MATLAB path.
Call jl.config any time you want to build against a different version of Julia. You can
pass in the path to the desired Julia executable to build against if you don't want
to be prompted to select one.
Quick start
Use jl.eval to parse and evaluate MATLAB strings as Julia expressions:
>> jl.eval('2+2')
ans =
int64
4
You can evaluate multiple expressions in a single call:
>> [s, c] = jl.eval('sin(pi/3)', 'cos(pi/3)')
s =
0.8660
c =
0.5000
Julia's STDOUT and STDERR are redirected to the MATLAB console:
Use jl.call to call a Julia function specified by its name as a string:
>> jl.call('factorial', 10)
ans =
3628800
jl.call marshals MATLAB data to/from Julia making certain default choices for doing so.
Load new Julia code by calling jl.include:
>> jl.include('my_own_julia_code.jl')
Exercise more control over how data is marshaled between MATLAB and Julia by defining
a Julia function with a "MEX-like" signature and invoking it with jl.mex:
The first argument to jl.mex is the number of return values to expect. The second is the name of the function to be invoked. All remaining arguments are treated as function arguments. jl.mex expects the functions on which it is invoked to accept a single argument of type Vector{MxArray} and to return an iterable collection of values on which mxarray may be successfully invoked (e.g., a value of type Vector{MxArray}).
See lmdif_test.m, lm.m, and lmdif.jl for a more complex example that exposes Optim.jl's Levenberg-Marquardt solver to MATLAB. It presents an example of a MATLAB function handle being passed to Julia and used as a
callback. (The default marshaling wraps matlab function handles in an anonymous function.)
Known Issues
On Windows, if a julia is on the path it must be the one against which mexjulia is built.
请发表评论