从调用Matlab的净对象(目录)的方法 [英] invoke Matlab object's (directory) method from .Net
问题描述
我定义了一类具有一堆存储在方法目录的方法。我可以实例化类和MATLAB中调用它的方法。不过,如果我尝试从.NET / COM做同样的我得到这个错误信息:
???参考不存在字段test'.\\\
\\\
下面的测试与方法。
我的类是从手柄来源,我已经试过两种可能性:类文件和目录的方法定义的方法。无论是作品!
任何意见将非常感激。 。非常感谢
PS:
C#代码:
MLApp.MLApp MATLAB =新MLApp.MLApp();
matlab.Execute(清;);
matlab.Execute(对象= 1类(););
串测试= matlab.Execute(Object.test());
工作MATLAB代码:
清晰;
=对象的Class1();
Object.test()
PPS:
只是双重检查,从C#代码调用时工作MATLAB脚本不工作:
Matlab的类定义:
classdef测试<处理
方法
功能[C,则obj =添加(OBJ,A,B)
C = A + B;
端
端%方法
端%classdef
MATLAB脚本
清晰;
测试=测试();
结果= Test.add(1,3);
C#代码:
MLApp.MLApp MATLAB =新MLApp.MLApp();
对象的结果;
matlab.Execute(清;);
matlab.Execute(测试=测试(););
matlab.Execute(结果= Test.add(1,3););
matlab.GetWorkspaceData(结果,基地,出结果);
原来,你不能使用相同的对象实例名称作为类名。所以:
MLApp.MLApp MATLAB =新MLApp.MLApp();
对象的结果;
matlab.Execute(清;);
matlab.Execute(X =测试(););
matlab.Execute(结果= X.add(1,3););
matlab.GetWorkspaceData(结果,基地,出结果);
作品! Mathworks公司提出了这个错误(他们可能会解决这一问题在将来的版本)。
基督教
I defined a class with a bunch of methods stored in a method directory. I can instantiate the class and invoke its methods within matlab. However, if I try to do the same from .NET/COM I get this error messages:
"??? Reference to non-existent field 'test'.\n\n"
Here test is the method.
My class is derived from handle and I have tried both possibilities: method defined in class file and directory method. Neither works!
Any feedback would be very much 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()");
Working matlab code:
clear;
Object = Class1();
Object.test()
PPS:
Just double checked that the working Matlab script is NOT working when invoked 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);
It turns out that you cannot use the same 'object instance name' as the 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);
works! Mathworks raised this an error (they may fix this in future releases).
Christian
这篇关于从调用Matlab的净对象(目录)的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!