C#调用MATLAB
要在C#中运行,但由于我是C#新手,我想打印C#调用MATLAB,c#,matlab,C#,Matlab,要在C#中运行,但由于我是C#新手,我想打印System.Array prresult=new double[4]的结果以下是使用MATLAB的C#代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1{ class Class1{ [STAThread] static void Main(stri
System.Array prresult=new double[4]的结果代码>以下是使用MATLAB的C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1{
class Class1{
[STAThread]
static void Main(string[] args){
MLApp.MLAppClass matlab = new MLApp.MLAppClass();
System.Array pr = new double[4];
pr.SetValue(11,0);
pr.SetValue(12,1);
pr.SetValue(13,2);
pr.SetValue(14,3);
System.Array pi = new double[4];
pi.SetValue(1,0);
pi.SetValue(2,1);
pi.SetValue(3,2);
pi.SetValue(4,3);
matlab.PutFullMatrix("a", "base", pr, pi);
System.Array prresult = new double[4];
System.Array piresult = new double[4];
matlab.GetFullMatrix("a", "base", ref prresult, ref piresult);
}
}
}
我在前后添加了这些行,如:
System.Array prresult = new double[4];
System.Array piresult = new double[4];
Console.Write(prresult);
Console.Write(piresult);
matlab.GetFullMatrix("a", "base", ref prresult, ref piresult);
Console.Write(prresult);
Console.Write(piresult);
我进入控制台:
System.Double[]System.Double[]System.Double[]System.Double[]系统
如何在console中打印正确的结果???类似以下内容:
foreach(var item in prresult)
{
Console.Write(item.ToString() + ", ");
}
PrintArray(prresult);
下面是一个函数,用于以类似MATLAB的语法输出数组元素:
static void PrintArray(double[] aArray)
{
var str = "";
for (int index = 0; index < aArray.Length; index++)
{
var item = aArray[index];
str += item.ToString();
if (index < aArray.Length - 1)
str += ", ";
}
Console.WriteLine("[" + str + "]");
}
我收到错误2参数“1”:无法将“System.Array”转换为“double[]”控制台应用程序1
如何更正此错误?将最后一行更改为打印数组((double[])prresult代码>