Modify data in matlab instance using MLApp and COM, C#

拈花ヽ惹草 提交于 2019-12-11 14:37:50

问题


C# application trying to reshape data in Matlab. In Matlab I need the data to appear 3-dimensional in the matlab instance. (The code assumes an instance of matlab is running.)

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)");
}

Is it possible to modify existing data in matlab at all with COM?


回答1:


Need to set the value in the execute method:

matlab.Execute(name + " = reshape (" + name + ",2,2)");


来源:https://stackoverflow.com/questions/31035378/modify-data-in-matlab-instance-using-mlapp-and-com-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!