juliamatlab / mexjulia

embedding Julia in the MATLAB process.
MIT License
52 stars 14 forks source link

undefined methods for MxArrays.MxArray type #55

Open agbondy opened 6 years ago

agbondy commented 6 years ago

I'm using mexjulia to call a julia function "compute_LL.jl" from matlab which takes a dict as an input. I'm passing it a Matlab struct, which gets converted sensibly to a dict but its fields, which are just arrays of doubles and logicals, get converted into MxArrays.MxArray which somehow no methods seem to be defined for. I think this type should inherit all the functionality of MATLAB.MxArray types but basic methods which are defined for those (I've tried length, subscript indexing) throw an "undefined method" error. I'm using Julia 0.6 and Matlab R2017a on a PC running Windows 10. I'm attaching the Julia module "DriftDiffusison" which contains the function compute_LL which I am calling.

When I call this function, I get: "MethodError: no method matching length(::MxArrays.MxArray)" on line 29 of the module.

The struct getting passed to this function looks like:

struct with fields:

   pokedR: [7487×1 logical]
 leftbups: {7487×1 cell}
rightbups: {7487×1 cell}
        T: [7487×1 double]

DriftDiffusion.zip

agbondy commented 6 years ago

OK, I'm still new to Julia but I think I have a better understanding of the problem now, and it is (I think) rather simpler than I thought. The problem is just that, currently, there is no functionality in mexjulia for dealing with composite types. IOW, a cell array in Matlab like { [5 6] [7 8] } gets sensibly converted to a julia array, but its elements don't get converted to julia types. They just end up as MxArrays.MxArray types, which Julia doesn't know how to deal with. Structured arrays also end up as MxArrays.MxArray types in Julia, causing problems. It seems like adding this functionality wouldn't be too hard -- mexjulia would just have to call jvalue recursively, each time checking its output to see if it needs to be run again.

twadleigh commented 6 years ago

That sounds right. Unfortunately I no longer have access to a MATLAB license, so I have no way to test any code tweaks myself.

agbondy commented 6 years ago

That's a shame! Working with proprietary software has definite downsides. Now that I've figured this out, I can scrape by as long as I keep my variables simple.