C#调用MATLAB dll绘制正弦图

chengyouli8243 2018-09-09 04:39:53
using test13; // test13 为MATLAB画图
test13.test1313class test13 = new test13.test1313class();

try
{
if (modelFlag)
{
MWNumericArray x = null;
Xlength1 = (double.Parse(textBox1_fenbian.Text));
x = new MWNumericArray(Xlength1);
test13.test13(x);
}
break;
}
catch (Exception eee)
{
MessageBox.Show("选择绘图数据有误!\n请检查后重新选择!");
var strr =(eee.ToString());
}
strr 报错如下:


请问大哥们怎么解决,小弟不胜感激
...全文
371 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengyouli8243 2018-09-15
  • 打赏
  • 举报
回复
引用 7 楼 shijies 的回复:
test13.test13?


shijies 2018-09-15
  • 打赏
  • 举报
回复
test13.test13?
chengyouli8243 2018-09-15
  • 打赏
  • 举报
回复
执行完test13.test13(xz)后,跳进catch (Exception eee)
chengyouli8243 2018-09-15
  • 打赏
  • 举报
回复
改了一下: int xz = 0;
int xzz = 0;
if (!string.IsNullOrEmpty(textBox1_fenbian.Text))
{
Xlength1 = (double.Parse(textBox1_fenbian.Text));
// x = new MWNumericArray(Xlength1);
xzz = (int)( Xlength1);
xz = xzz;
test13.test13(xz);
}

得到值了把?但还是去报错了?
把报错再粘一下:
System.ArgumentNullException: 值不能为空。
参数名: source
在 System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)
在 MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(String functionName, Int32 numArgsOut, Int32 numArgsIn, MWArray[] argsIn)
在 MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(Int32 numArgsOut, String functionName, MWArray[] argsIn)
在 test13.test1313class.test13(Int32 numArgsOut)
chengyouli8243 2018-09-15
  • 打赏
  • 举报
回复
引用 5 楼 chengyouli8243 的回复:
改了一下: int xz = 0;
int xzz = 0;
if (!string.IsNullOrEmpty(textBox1_fenbian.Text))
{
Xlength1 = (double.Parse(textBox1_fenbian.Text));
// x = new MWNumericArray(Xlength1);
xzz = (int)( Xlength1);
xz = xzz;
test13.test13(xz);
}

得到值了把?但还是去报错了?
把报错再粘一下:
System.ArgumentNullException: 值不能为空。
参数名: source
在 System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)
在 MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(String functionName, Int32 numArgsOut, Int32 numArgsIn, MWArray[] argsIn)
在 MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(Int32 numArgsOut, String functionName, MWArray[] argsIn)
在 test13.test1313class.test13(Int32 numArgsOut)



https://wenku.baidu.com/view/fc23ef2aaf45b307e8719752.html
从此文档中发现是MATLAB.m文件中函数声明有个输出,C#中没有,故没对接上。
shijies 2018-09-10
  • 打赏
  • 举报
回复
strr 报错的子太小了,看不清楚。
threenewbee 2018-09-09
  • 打赏
  • 举报
回复
x = new MWNumericArray(Xlength1);
这个调试下,为什么没有得到值
chengyouli8243 2018-09-09
  • 打赏
  • 举报
回复
不好意思,本人还是小白,在摸索阶段,请问source 参数 是指的哪个参数?
SoulRed 2018-09-09
  • 打赏
  • 举报
回复
你传入的source 参数是个null值。。。。很基础的错误。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧