使用c#中的进程运行多个matlab脚本

时间:2015-06-26 09:16:29

标签: c# matlab process

所以我有一个matlab脚本初始化一些值然后我想运行另一个matlab脚本。有没有办法告诉我的进程在第一个脚本之后运行另一个脚本。

这是我的代码,它运行正常但只运行一个脚本。

ProcessStartInfo info = new ProcessStartInfo(@"matlab.exe", @"-r script1");
Process process = new Process();
process.StartInfo = info;
process.EnableRaisingEvents = true;              
process.Start();
process.WaitForExit();
process.Exited += new EventHandler(myProcess_Exited);
evHandledGetLatest = process.HasExited;

如何在script1运行script2之后? 我想在同一个进程中运行script1和script2,script2需要有script1创建的值(在matlab工作区中)。

1 个答案:

答案 0 :(得分:1)

If I were you I'd strongly consider calling the Matlab script directly from C#. This approach will allow you to get the results from script1 and pass them to script2.

You'll need to add a reference to the Matlab COM object.

For full details see: http://www.mathworks.com/help/matlab/matlab_external/call-matlab-function-from-c-client.html