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

📄 多项式拟合.frm

📁 vb调用matlab——多项式拟合 vb调用matlab——多项式拟合
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "多项式拟合 "
   ClientHeight    =   5790
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8175
   BeginProperty Font 
      Name            =   "MS Sans Serif"
      Size            =   12
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   5790
   ScaleWidth      =   8175
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command3 
      Caption         =   "退出"
      Height          =   615
      Left            =   5160
      TabIndex        =   12
      Top             =   4800
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "绘图"
      Height          =   615
      Left            =   3120
      TabIndex        =   11
      Top             =   4800
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "计算"
      Height          =   615
      Left            =   1080
      TabIndex        =   10
      Top             =   4800
      Width           =   1095
   End
   Begin VB.TextBox Text5 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   5880
      TabIndex        =   9
      Text            =   "1"
      Top             =   480
      Width           =   1215
   End
   Begin VB.TextBox Text4 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   525
      Left            =   1320
      TabIndex        =   8
      Text            =   "Text4"
      Top             =   3840
      Width           =   5895
   End
   Begin VB.TextBox Text3 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   525
      Left            =   1440
      TabIndex        =   7
      Text            =   "12 24 43 57 70 91 110 200"
      Top             =   2160
      Width           =   5775
   End
   Begin VB.TextBox Text2 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   525
      Left            =   1440
      TabIndex        =   6
      Text            =   "1 2 3 4 5 6 7 8"
      Top             =   1320
      Width           =   5775
   End
   Begin VB.TextBox Text1 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   1440
      TabIndex        =   5
      Text            =   "8"
      Top             =   480
      Width           =   1695
   End
   Begin VB.Label Label5 
      Caption         =   "多项式系数和常数"
      Height          =   375
      Left            =   600
      TabIndex        =   4
      Top             =   3240
      Width           =   2175
   End
   Begin VB.Label Label4 
      Caption         =   "Y"
      Height          =   255
      Left            =   960
      TabIndex        =   3
      Top             =   2280
      Width           =   255
   End
   Begin VB.Label Label3 
      Caption         =   "X"
      Height          =   255
      Left            =   960
      TabIndex        =   2
      Top             =   1320
      Width           =   255
   End
   Begin VB.Label Label2 
      Caption         =   "多项式的阶次"
      Height          =   255
      Left            =   4440
      TabIndex        =   1
      Top             =   480
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "数据组数"
      Height          =   255
      Left            =   480
      TabIndex        =   0
      Top             =   480
      Width           =   735
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'进行多项式拟合
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
'创建matlab实例
Private Sub Form_Initialize()
'Set objMATLAB = CreateObject("matlab.application")
End Sub

Private Sub Form_Load()

'Set objMATLAB = CreateObject("matlab.application")

'将matlab实例对象定义为公共变量
Dim objMATLAB As Object

End Sub

'定义一个实现计算或绘图的过程
Private Sub ComputeorPlot(CorP As Boolean)
Set objMATLAB = CreateObject("matlab.application")
'Dim objMATLAB As Object
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.Text)
intLevel = Val(Text5.Text)

Open App.Path + "/datX" For Output As 1
   Print #1, Form1.Text2
Close 1

Open App.Path + "/datY" For Output As 1
   Print #1, Form1.Text3
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


'定义在matlab中要执行的命令
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)"
   Text4 = objMATLAB.execute(strCommand)
Else
   strCommand = strCommand & "plot(x,y)"
   objMATLAB.execute (strCommand)
End If



    
End Sub

⌨️ 快捷键说明

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