误差集成MATLAB和Visual Basic



程序很简单,只需添加两个数字即可。这是我在.NET组装中创建和内置的MATLAB函数

function out = addMe(a,b)
out = a+b;
end

i然后使用NE Builder工具箱生成.NET组件:http://imagizer.imageshack.us/v2/800x600q90/823/f77h.jpg

Imports Add
Public Class Form1
    Dim a As Integer = 5
    Dim b As Integer = 10
    Dim res
    Dim addme As New AddClass
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        res = addme.addMe(a, b)
        TextBox1.Text = res
    End Sub
End Class

但是当我运行程序时,我会遇到此错误:

System.InvalidOperationException was unhandled
  HResult=-2146233079
  Message=An error occurred creating the form. See Exception.InnerException for details.  The error is: Could not load type 'Add.AddClass' from assembly 'Add, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
  Source=Add
  StackTrace:
       at Add.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
       at Add.My.MyProject.MyForms.get_Form1()
       at Add.My.MyApplication.OnCreateMainForm() in c:userselvin gentilesdocumentsvisual studio 2013ProjectsAddAddMy ProjectApplication.Designer.vb:line 35
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at Add.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.TypeLoadException
       HResult=-2146233054
       Message=Could not load type 'Add.AddClass' from assembly 'Add, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
       Source=Add
       TypeName=Add.AddClass
       StackTrace:
            at Add.Form1..ctor()
       InnerException: 

您需要在.NET应用程序中添加所需的MATLAB组件才能运行MATLAB功能。

遵循此链接,我创建了可能会给您一些有关添加MATLAB组件的想法:

http://www.youtube.com/watch?v=v-hmkmnsk88(第2部分)

http://www.youtube.com/watch?v=gyj7q4linyw(第1部分)

希望这会有所帮助。

最新更新