当前位置:编程学习 > C#/ASP.NET >>

C#调用matlab elman神经网络错误

最近在用c#与matlab混合编程,用matlab模拟实现了elman神经网络来预测数据。但是在用c#调用写好的函数时出现错误。我已经将.m文件编程为dll并在vs中添加引用了。我的.m文件代码为:function elman_test()
P=[0.3147 0.3151 0.3436 0.3661 0.3051 0.3609 0.3528 0.3585 0.3151 0.3679 0.3569 0.3500;
   0.3051 0.3609 0.3528 0.3585 0.3151 0.3679 0.3569 0.3500 0.3361 0.3756 0.3632 0.3657;
   0.3151 0.3679 0.3569 0.3500 0.3361 0.3756 0.3632 0.3657 0.3394 0.3523 0.3587 0.3325;]';
T=[0.3361 0.3756 0.3632 0.3657;
   0.3394 0.3523 0.3587 0.3325;
   0.3369 0.3681 0.3519 0.3369]';
F=[0.3361 0.3756 0.3632 0.3657 0.3394 0.3523 0.3587 0.3325 0.3369 0.3681 0.3519 0.3369]';
threshold=[0 1;0 1;0 1; 0 1; 0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1];
a=[12 18 24];
for i= 1:3 
   net=newelm(threshold,[a(i),4],{'tansig','purelin'});
net.trainParam.epochs=1000;
net=init(net);
net=train(net,P,T);

end

x=sim(net,F);

c#中调用该函数的代码为:
Elmantest elmantest = new Elmantest();
             elmantest.elman_test();
编译时可以通过,但是每次运行的时候总会出错,出错的地方是在net=newelm();这个地方。刚开始是有下面这个错误:....cannot be set to non-existing function mse....我找到mse.m这个文件后,在编译成dll文件时加上去了,加上去之后出现下面这个错误:

未处理 System.Exception
  Message="\n\n... MWMCR::EvaluateFunction error ... \nOutput argument \"err\" (and maybe others) not assigned during call to \"C:\\Users\\LN\\AppData\\Local\\Temp\\LN\\mcrCache7.10\\elmant8\\toolbox\\nnet\\nnet\\@network\\subsasgn.m>setAdaptFcn\".\nError in =>elman_test.m at 12.\n\n... Matlab M-code Stack Trace ...\n    at\nfile C:\\Users\\LN\\AppData\\Local\\Temp\\LN\\mcrCache7.10\\elmant8\\toolbox\\nnet\\nnet\\@network\\subsasgn.m,name subsasgn,line at 435.\n    at\nfile C:\\Users\\LN\\AppData\\Local\\Temp\\LN\\mcrCache7.10\\elmant8\\toolbox\\nnet\\nnet\\nnnetwork\\newelm.m,name new_5p0,line at 251.\n    at\nfile C:\\Users\\LN\\AppData\\Local\\Temp\\LN\\mcrCache7.10\\elmant8\\toolbox\\nnet\\nnet\\nnnetwork\\newelm.m,name newelm,line at 99.\n    at\nfile C:\\Users\\LN\\AppData\\Local\\Temp\\LN\\mcrCache7.10\\elmant8\\Users\\LN\\Desktop\\elman_test.m,name elman_test,line at 12.\n\n"
  Source="MWArray"
  StackTrace:
       在 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)
       在 elmantest.Elmantest.elman_test()
       在 WindowsFormsApplication2.Form1.button1_Click(Object sender, EventArgs e) 位置 D:\交通所\Test\matlab\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs:行号 55
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 WindowsFormsApplication2.Program.Main() 位置 D:\交通所\Test\matlab\WindowsFormsApplication2\WindowsFormsApplication2\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
不知道有没有人遇到类似的问题,麻烦帮忙看一下,非常感谢            --------------------编程问答-------------------- 怎么没人回答啊,急 啊 --------------------编程问答--------------------
引用 1 楼 zhenwoln 的回复:
怎么没人回答啊,急 啊
。。不知道。。帮顶 --------------------编程问答-------------------- 想知道调用神经网络做啥 --------------------编程问答-------------------- 提供一个查找问题的思路
你可以先在MATLAB里面把东西都调试过了。
然后再往C#里面用。




神经网络的用处很广,多数用于一些智能算法里面。

--------------------编程问答-------------------- 我也不知,到处学习,希望遇到大侠 --------------------编程问答-------------------- 同意楼上 --------------------编程问答--------------------
引用 3 楼 csf864531670 的回复:
想知道调用神经网络做啥

我是想用神经网络来预测交通流量,不知道有什么好的方法没 --------------------编程问答--------------------
引用 4 楼 wodegege10 的回复:
提供一个查找问题的思路
你可以先在MATLAB里面把东西都调试过了。
然后再往C#里面用。




神经网络的用处很广,多数用于一些智能算法里面。


我在matlab里面调试都是好的,也可以运行,不知道在c#里一调用matlab的可以运行的函数就会出错,谢谢 --------------------编程问答-------------------- 楼主的问题解决了吗? --------------------编程问答-------------------- 我也在用.net调用MATLAB神经网络,有空交流下qq:334129862
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,