⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vb_matlab.frm

📁 VB与MATLAB接口使用实例.保准一学就会。
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8775
   ClientLeft      =   60
   ClientTop       =   420
   ClientWidth     =   13545
   LinkTopic       =   "Form1"
   ScaleHeight     =   8775
   ScaleWidth      =   13545
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text5 
      Height          =   855
      Left            =   1920
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   12
      Top             =   4680
      Width           =   5895
   End
   Begin VB.CommandButton Command3 
      Caption         =   "退出"
      Height          =   855
      Left            =   8760
      TabIndex        =   11
      Top             =   6120
      Width           =   1935
   End
   Begin VB.CommandButton Command2 
      Caption         =   "绘图"
      Height          =   855
      Left            =   4560
      TabIndex        =   10
      Top             =   6120
      Width           =   1815
   End
   Begin VB.CommandButton Command1 
      Caption         =   "计算"
      Height          =   735
      Left            =   840
      TabIndex        =   9
      Top             =   6120
      Width           =   1695
   End
   Begin VB.TextBox Text4 
      Height          =   615
      Left            =   2040
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   8
      Text            =   "VB_MATLAB.frx":0000
      Top             =   3360
      Width           =   5655
   End
   Begin VB.TextBox Text3 
      Height          =   735
      Left            =   2040
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   7
      Text            =   "VB_MATLAB.frx":001C
      Top             =   2400
      Width           =   5655
   End
   Begin VB.TextBox Text2 
      Height          =   615
      Left            =   7440
      TabIndex        =   6
      Text            =   "1"
      Top             =   240
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      Height          =   615
      Left            =   2280
      TabIndex        =   5
      Text            =   "8"
      Top             =   240
      Width           =   1575
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "多项式系数和常数项"
      Height          =   180
      Left            =   1560
      TabIndex        =   4
      Top             =   4320
      Width           =   1620
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "Y"
      Height          =   180
      Left            =   1560
      TabIndex        =   3
      Top             =   3480
      Width           =   90
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "X"
      Height          =   180
      Left            =   1560
      TabIndex        =   2
      Top             =   2760
      Width           =   90
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "多项式的阶次"
      Height          =   180
      Left            =   6240
      TabIndex        =   1
      Top             =   480
      Width           =   1080
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据组数"
      Height          =   180
      Left            =   1320
      TabIndex        =   0
      Top             =   480
      Width           =   720
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public objmatlab As Object
Private Sub computeorplot(corp As Boolean)
    Dim intnum As Integer
    Dim intlevel As Integer
    Dim x(1 To 100) As Double
    Dim y(1 To 100) As Double
    Dim strmodel As String
    Dim i As Integer
    Dim strcommand As String
    
    intnum = Val(Text1)
    intlevel = Val(Text2)
    Open App.Path + "/datX" For Output As 1
     Print #1, Form1.Text3
    Close 1
     Open App.Path + "/datY" For Output As 1
     Print #1, Form1.Text4
    Close 1
    
     Open App.Path + "/datX" For Input As 1
     For i = 1 To intnum
        Input #1, x(i)
     Next i
     Close 1
     Open App.Path + "/datY" For Input As 1
     For i = 1 To intnum
        Input #1, y(i)
     Next i
     Close 1
    
    strcommand = "n=" & Str(intlevel) & ";x=["
    For i = 1 To intnum
        strcommand = strcommand & Str(x(i)) & ""
    Next i
    strcommand = strcommand & "];y=["
    For i = 1 To intnum
        strcommand = strcommand & Str(y(i)) & ""
    Next i
    strcommand = strcommand & "];"
    If corp Then
       strcommand = strcommand & "polyfit(x,y,n)"
       Text5 = objmatlab.execute(strcommand)
       'Text5 = strcommand
    Else
       strcommand = strcommand & "plot(x,y)"
      objmatlab.execute (strcommand)
      'Text5 = strcommand
    End If
    
End Sub

Private Sub Command1_Click()
Dim bolcorp As Boolean
bolcorp = True
Call computeorplot(bolcorp)
End Sub

Private Sub Command2_Click()
Dim bolcorp As Boolean
bolcorp = False
Call computeorplot(bolcorp)

End Sub

Private Sub Command3_Click()
Set objmatlab = Nothing
Unload Form1
End Sub

Private Sub form_initialize()
  Set objmatlab = CreateObject("matlab.application")
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -