使用MLApp和COM,C#在matlab实例中修改数据
本文关键字:实例 matlab 修改 数据 MLApp COM 使用 | 更新日期: 2023-09-27 17:59:24
C#应用程序试图在Matlab中重塑数据。在Matlab中,我需要数据在Matlab实例中出现三维。(该代码假设matlab的一个实例正在运行。)
public void PassAndResizeInMatlab()
{
MLApp.MLApp matlab = (MLApp.MLApp)Marshal.GetActiveObject("Matlab.Desktop.Application");
matlab.Execute("enableservice('AutomationServer',true);");
var dat = new double[]{1,2,3,4};
var name = "myexample";
//matlab does not support passing double[,,] with this function.
matlab.PutWorkspaceData(name, "base", dat);
object varargout;
//this fails
matlab.Feval("reshape", 1, out varargout, name, new double[]{2,2});
//works but does not put the value in the matlab instance.
matlab.Feval("ones", 1, out varargout, 3,4,5); //works
//works but does not put the value in the matlab instance.
var output = matlab.Execute("reshape (" + name + ",2,2)");
}
是否可以使用COM修改matlab中的现有数据?
需要在execute方法中设置值:
matlab.Execute(name + " = reshape (" + name + ",2,2)");