你几乎已经明白了,但matlab.Execute("cd d:\textcreator.m")你应该,而不是matlab.Execute("cd d:\"),然后matlab.Execute("run textcreator.m")。所以你的代码应该是:MLApp.MLApp matlab = new MLApp.MLApp(); matlab.Execute("cd d:\");matlab.Execute("run textcreator.m");我还挖出了我很久以前写的一个简单的 MLApp 包装器。认为它会对你有用。class MLWrapper{ private readonly MLApp.MLApp _mlapp; public MLWrapper(bool visible = false) { _mlapp = new MLApp.MLApp(); if (visible) ShowConsole(); else HideConsole(); } ~MLWrapper() { Run("close all"); _mlapp.Quit(); } public void ShowConsole() { _mlapp.Visible = 1; } public void HideConsole() { _mlapp.Visible = 0; } /// <summary> /// Run a MATLAB command. /// </summary> /// <returns>Text output displayed in MATLAB console.</returns> public string Run(string cmd) { return _mlapp.Execute(cmd); } /// <summary> /// Run a MATLAB script. /// </summary> /// <returns>Text output displayed in MATLAB console.</returns> public string RunScript(string scriptName) { return Run($"run '{scriptName}'"); } /// <summary> /// Change MATLAB's current working folder to the specified directory. /// </summary> public void CD(string directory) { Run($"cd '{directory}'"); } public object GetVariable(string varName) { _mlapp.GetWorkspaceData(varName, "base", out var data); return data; } public void SetVariable(string varName, object value) { _mlapp.PutWorkspaceData(varName, "base", value); }}
1 回答
汪汪一只猫
TA贡献1898条经验 获得超8个赞
如果您想“关闭”其内容显示在 RichTextBox 中的文件,我认为清除 RichTextBox 并释放您的资源就足够了。
例如,通过“处置您的资源”,我的意思是关闭您的资源FileStream
或将其包装在 中using
。
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报
0/150
提交
取消