本文介绍了使用MLApp和COM,C#在matlab实例中修改数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#应用程序试图在Matlab中重塑数据.在Matlab中,我需要数据在Matlab实例中显示为 3D维度. (代码假定正在运行matlab的实例.)

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

是否可以通过COM完全修改matlab中的现有数据?

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

推荐答案

需要在execute方法中设置值:

Need to set the value in the execute method:

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

这篇关于使用MLApp和COM,C#在matlab实例中修改数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:46