Call Matlab object method (directory) from .Net

I defined a class with a bunch of methods stored in the method directory. I can create an instance of the class and call its methods in Matlab. However, if I try to do the same with .NET / COM, I get the following error messages:

"??? Reference to non-existent field 'test'.\n\n" 

Here test is a method.

My class is derived from a descriptor, and I tried both possibilities: the method defined in the class method and the directory. Nothing works!

Any feedback would be greatly appreciated. Many thanks.

PS:

C # code:

 MLApp.MLApp matlab = new MLApp.MLApp(); matlab.Execute("clear;"); matlab.Execute("Object = Class1();"); string test = matlab.Execute("Object.test()"); 

Matlab working code:

 clear; Object = Class1(); Object.test() 

PPS:

Just double check that the working Matlab script does NOT work when called from C # code:

Matlab class definition:

 classdef Test < handle methods function [c, obj] = add(obj, a, b) c = a + b; end end % methods end %classdef 

Matlab script:

 clear; Test = Test(); result = Test.add(1, 3); 

C # code:

 MLApp.MLApp matlab = new MLApp.MLApp(); object result; matlab.Execute("clear;"); matlab.Execute("Test = Test();"); matlab.Execute("result = Test.add(1, 3);"); matlab.GetWorkspaceData("result", "base", out result); 
+7
source share
1 answer

Turns out you can't use the same instance name of an object as a class name. So:

 MLApp.MLApp matlab = new MLApp.MLApp(); object result; matlab.Execute("clear;"); matlab.Execute("X = Test();"); matlab.Execute("result = X.add(1, 3);"); matlab.GetWorkspaceData("result", "base", out result); 

working! Mathworks raised this error (they may fix this in future releases).

Christian

+5
source

All Articles