C#调用Matlab程序
MLApp.MLApp matlab = null; Type matlabAppType = System.Type.GetTypeFromProgID("Matlab.Application"); matlab = System.Activator.CreateInstance(matlabAppType) as MLApp.MLApp; string path_project = Directory.GetCurrentDirectory(); Console.WriteLine(path_project);//matlab程序放在这个目录下 string path_matlab = "cd('" + path_project + "')"; matlab.Execute(path_matlab); string cmd = @"[count1,count2,count3,count5]=netGetResult()";//matlab命令,前面为返回参数,后面为执行方法 matlab.Execute("clear all"); matlab.Execute(cmd); var result1 = matlab.GetVariable("count1", "base"); var result2 = matlab.GetVariable("count2", "base"); var result3 = matlab.GetVariable("count3", "base"); var result5 = matlab.GetVariable("count5", "base");