Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#matlab参考,日记不工作_C#_Matlab - Fatal编程技术网

使用c#matlab参考,日记不工作

使用c#matlab参考,日记不工作,c#,matlab,C#,Matlab,因此,我在我的c#代码中使用matlab,但当我使用日记时,它将创建一个文件,但它将是emtpy。我发现了一个简单的问题,但还没有找到解决办法 我的代码 MLApp.MLApp matlab = new MLApp.MLApp(); matlab.Execute("diary"); matlab.Execute("disp('heej')"); ... ... matlab.Execute("disp('heej')"); matlab.Execute("disp('heej')"); mat

因此,我在我的c#代码中使用matlab,但当我使用日记时,它将创建一个文件,但它将是emtpy。我发现了一个简单的问题,但还没有找到解决办法

我的代码

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

matlab.Execute("diary");
matlab.Execute("disp('heej')");
...
...
matlab.Execute("disp('heej')");
matlab.Execute("disp('heej')");
matlab.Execute("disp('heej')");
matlab.Execute("diary off");

有没有关于如何使用c#应用程序中的日志的想法?

因此,从c#应用程序运行日志时,日志似乎不起作用,但是您可以使用c#本身来保存Matlab提供的输出。我使用Trace将输出发送到终端和文本文件

        Trace.Listeners.Clear();

        TextWriterTraceListener twtl = new TextWriterTraceListener(pathBuildDir + @"\log.txt");
        twtl.Name = "TextLogger";
        twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;

        ConsoleTraceListener ctl = new ConsoleTraceListener(false);
        ctl.TraceOutputOptions = TraceOptions.DateTime;

        Trace.Listeners.Add(twtl);
        Trace.Listeners.Add(ctl);
        Trace.AutoFlush = true;

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

        Trace.WriteLine(matlab.Execute("pwd"));
        Trace.WriteLine(matlab.Execute(@"run('foobar.m')"));
        ...
        ...