C# C语言中MATLAB函数返回矩阵值的求法#
我试图用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
// 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'.
如何在返回的对象中访问和引入值