用c#编写的dll函数的matlab代码
本文关键字:函数 matlab 代码 dll | 更新日期: 2023-09-27 18:13:11
我有一个c#项目,我想在matlab中使用我的项目的函数。我添加了
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
在我的项目中的每个类之前,并使输出类型类库。但是当我在matlab中使用dll时,
temp = NET.addAssembly('../../foo')
然后是foo.Classes
,没有类!我该怎么办?!请帮帮我:)
关于上述注释的示例
要使用NET.addAssembly(...)
使用。net程序集中的类,不需要使类COM可见,但该类,以及您想要访问的方法必须是public。
。NET代码
namespace foo
{
public class SampleClass
{
// Constructor
public SampleClass() { }
// Static example
public static string StaticMethod() { return "Hello from static method."; }
// Instance example
public string InstanceMethod() { return "Hello from instance method."; }
}
}
Matlab中的用法
% Loading the .NET assembly
NET.addAssembly('..'..'Foo.dll');
% Call of a static method
foo.SampleClass.StaticMethod()
% Call of an instance method
instance = foo.SampleClass();
instance.InstanceMethod();