日期:2014-05-18  浏览次数:20791 次

C#与matlab混合编程遇到了点问题(欢迎熟悉matlab的朋友)
配置完毕后 
====================
写了个求离散积分的.m 文件
function y=myint1(value,n)
t=0:1:n-1;
x=value;
y=cumtrapz(t,x);  
=====================
DLL文件名称是:MatMagic1
=====================
C#中的测试代码
MatMagic1.MatMagic1 m = new MatMagic1.MatMagic1();
  double[] x = new double[6] { 1, 2, 3, 4, 5, 6 };
  int n = 6;
  object argsOut, argsIn;
  argsIn = x;
  MWNumericArray y = new MWNumericArray(new double[]{3});
  argsOut = y;
  m.myint1(1, ref argsOut, argsIn,n);
========================

问题是:
  然后程序报错:Integers can only be combined with integers of the same class,or scalar doubles.
  Error in=>myint1.m at line 4.
我希望得到的是:m文件y返回的数组.
注:由于对matlab不是很熟悉 说得不专业的地方 望见谅。


------解决方案--------------------
1、在matlab中测试myint1,确保函数没有问题。
2、这个错误以前见过,貌似是矩阵数据是uint8类型的,是不能直接参与计算的,需要转换成double 类型的。


------解决方案--------------------
参考:
http://www.ilovematlab.cn/thread-10575-1-1.html