Matlab调用C#封装的dll文件(入门级)

实现步骤:

1.  在VS里创建类库工程,生成testMatlab.dll

namespace testMatlab
{
    public class Test
    {
        public static string showInfo()
        {
            return "luna luna";
        }
        public string showInfo1()
        {
            return "will will";
        }

    }
}

2. 打开matlab编写m文件,运行。

NET.addAssembly('G:\Matlab\testMatlab\testMatlab\bin\Debug\testMatlab.dll');
%调用静态方法
testMatlab.Test.showInfo()
%调用非静态方法
obj=testMatlab.Test
obj.showInfo1()

和C#类似,调用静态方法直接调用即可,调用非静态方法需要声明对象。运行结果如下:

                                              

这里主要介绍方法,掌握matlab调用C# dll的方式。


猜你喜欢

转载自blog.csdn.net/weixin_42183571/article/details/80587417