你幾乎已經(jīng)明白了,但matlab.Execute("cd d:\textcreator.m")你應(yīng)該,而不是matlab.Execute("cd d:\"),然后matlab.Execute("run textcreator.m")。所以你的代碼應(yīng)該是:MLApp.MLApp matlab = new MLApp.MLApp(); matlab.Execute("cd d:\");matlab.Execute("run textcreator.m");我還挖出了我很久以前寫的一個(gè)簡單的 MLApp 包裝器。認(rèn)為它會(huì)對你有用。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貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊
如果您想“關(guān)閉”其內(nèi)容顯示在 RichTextBox 中的文件,我認(rèn)為清除 RichTextBox 并釋放您的資源就足夠了。
例如,通過“處置您的資源”,我的意思是關(guān)閉您的資源FileStream
或?qū)⑵浒b在 中using
。
- 1 回答
- 0 關(guān)注
- 138 瀏覽
添加回答
舉報(bào)
0/150
提交
取消