自动化服务器函数:交换矩阵数据

GetFullMatrix和PutFullMatrix函数从MATLAB获取矩阵数据,以及将矩阵数据写入MATLAB。调用函数时,需要传递要读写的变量的名称,以及包含数据的工作空间的名称。

VB.NET中使用下面的语句行执行MATLAB命令。

code.vb.net
Dim objM As MLApp.MLApp
Dim Result As String
Dim dblAReal(3, 3) As Double
Dim dblAImag(3, 3) As Double
Dim strR As String = ""
objM = New MLApp.MLApp
Result = objM.Execute("A=rand(4);")
objM.GetFullMatrix("A", "base", dblAReal, dblAImag)
For intI = 0 To 3
    strR = strR & CStr(dblAReal(0, intI)) & vbCrLf
Next intI
MsgBox(strR)

VC#.NET中使用下面的语句行执行MATLAB命令。

code.vc#.net
MLApp.MLApp objM;
string Result;
double[,] dblAReal = new double[4, 4];
double[,] dblAImag = new double[4, 4];
string strR = "";
objM = new MLApp.MLApp();
Result = objM.Execute("A=rand(4);");
objM.GetFullMatrix("A", "base", ref dblAReal, ref dblAImag);
for(int intI = 0; intI <= 3; intI++)
{
    strR = strR + dblAReal[0, intI].ToString() + "\n";
}
MessageBox.Show(strR);