2

I'm trying to do a proof of concept with MATLAB objects. I want to see if you can use MATLAB objects like the one below in Java code. We need the MATLAB objects to keep state. I've used MATLAB Builder JA to create functions in MATLAB and access them in Java, but I'm not sure if MATLAB classes can be sent the same way.

classdef TestObject < handle
  properties (SetAccess = private)
      number = 0;
  end

  methods

      function addToNumber(TO, x)

          TO.number = TO.number + x;
      end
  end
end % classdef

1 Answer 1

2

I believe you currently can't do this. You can use MATLAB objects, but if you want to call their methods you need to create a functional wrapper for them, and they won't keep state between calls.

I think I'm right in saying that with Builder for .NET, rather than for Java, you have the ability to pass a .NET object across the boundary to MATLAB, a functionality which you can use to keep whatever state you would have done with a MATLAB object. You might be able to do something similar with a Java object using Builder for JA, but I've never tried it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Could you point me to some documentation to be able to call this class from Java. I can use Builder JA to use methods and structs just not Objects.
I don't know of an example in the documentation that shows how to call classes explicitly. In general, you would create a class as you have above, and then implement a function addToNumberWrapper(x), which creates an instance TO of TestObject and calls TO.addToNumber(x). Then deploy that wrapper function with Builder JA.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.