Matlab函数:
function[dstmat,answ]=MatrixMultiply(scamat1,srcmat2)
dstmat=scamat1*srcmat2;
dstmat=double(SubFun(dstmat));
answ=[1,2;3,4];
end
function dstmat=SubFun(srcmat)
dstmat=srcmat*1;
end
C#中的部分代码:
double[,]srcMat1 = new double[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
double[,]srcMat2 = new double[3, 3] { { 9, 8, 7 }, { 6, 5, 4 }, { 3, 2, 1 } };
MyClassmultiTest = new MyClass();
MWArray[] agrsOut = new MWArray[2]; //两个输出参数,一定要写数量
//输出几个输出参数可以是不同类型的,比如第一个元素是矩阵,第二个是数值
MWArray[]agrsIn = new MWArray[] { (MWNumericArray)srcMat1, (MWNumericArray)srcMat2 };
//同理,输入参数也是一个MWArray数组
multiTest.MatrixMultiply(2,ref agrsOut, agrsIn);
//调用函数,输出参数需要加 ref 关键字
//2表示输入参数的个数,输出结构都在argsOut中,类似于c的指针参数输入
MWNumericArray x1 = agrsOut[0] asMWNumericArray;
MWNumericArray x2 = agrsOut[1] asMWNumericArray;
//转换得到实际的输出参数,下标从0开始
double[,] c = (double[,])x1.ToArray();
double[,] d = (double[,])x2.ToArray();
//转换得到C#中可用的实际的输出参数