C#调用Matlab

在C#中调用Matlab, 需要先配置一下Matlab编译器, 然后在VS里面引用Matlab组件

具体操作如下:

1. 配置matlab编译工作

- mbuild -setup

- deploytool

根据Matlab版本不同命令有所不同, 输入上述命令后, 请根据提示选择.

2. 在VS里面引用Matlab组件

引用   .Net MWArray API (不是必须)

引用Matlab Application Type Library

using MathWorks;

using MathWorks.MATLAB;

using MathWorks.MATLAB.NET.Arrays;

using MathWorks.MATLAB.NET.Utility;

using MLApp;

private void button1_Click(object sender, EventArgs e)

        {

            MLApp.MLAppClass matlab = new MLApp.MLAppClass();

            string command;

            command = "t=2:0.2:4*pi;y=sin(t);plot(t,y)";

          

            matlab.Visible = 1;            

            matlab.Execute(command);        // 执行Matlab命令

            command = @"print(gcf,   '-djpeg',   'c:\Test1')";      // 保存图片

            matlab.Execute(command);

            matlab.Quit();

            matlab = null;

            pictureBox1.Image = Image.FromFile(@"c:\Test1.jpg");     

        }

猜你喜欢

转载自blog.csdn.net/dyxcome/article/details/82291880