Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中MATLAB函数返回矩阵值的求法#_C#_Matlab - Fatal编程技术网

C# C语言中MATLAB函数返回矩阵值的求法#

C# C语言中MATLAB函数返回矩阵值的求法#,c#,matlab,C#,Matlab,我试图用C#调用一个MATLAB函数。我成功地运行了一个简单的示例,其中返回了一个值,但我想返回一个向量和一个矩阵。我该怎么做 // Create the MATLAB instance MLApp.MLApp matlab = new MLApp.MLApp(); // Change to the directory where the function is located matlab.Execute(@"cd c:\MATLABcodevisualstudio"); // Def

我试图用C#调用一个MATLAB函数。我成功地运行了一个简单的示例,其中返回了一个值,但我想返回一个向量和一个矩阵。我该怎么做

// Create the MATLAB instance 
MLApp.MLApp matlab = new MLApp.MLApp();

// Change to the directory where the function is located 
matlab.Execute(@"cd c:\MATLABcodevisualstudio");

// Define the output 
object result = null;

// Call the MATLAB function myfunc
matlab.Feval("test", 2 , out result, 3.14, 42.0,"world");

// double[,] arr = (double[,])((MWNumericArray)result).ToArray(MWArrayComponent.Real); // if i use this it returns error 

// Display result 
object[] res = result as object[];
现在,结果将在
对象结果
双[,]
)中返回。我想从这个双数组中获取值,并将它们用于其他计算,然后将它们写入.csv文件。然而,当我尝试

 double[,] arr = (double[,])((MWNumericArray)result).ToArray(MWArrayComponent.Real);
它给出了一个错误

Additional information: Unable to cast object of type
'System.Object[]' to type
'MathWorks.MATLAB.NET.Arrays.MWNumericArray'.
如何在返回的对象中访问和引入值