📄 frmvbole.frm
字号:
VERSION 5.00
Begin VB.Form frmVBOLE
Caption = "VB调用MATLAB--多项式拟合"
ClientHeight = 4950
ClientLeft = 60
ClientTop = 345
ClientWidth = 6105
LinkTopic = "Form1"
ScaleHeight = 4950
ScaleWidth = 6105
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "退 出"
Height = 375
Left = 3960
TabIndex = 12
Top = 4200
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "绘 图"
Height = 375
Left = 2400
TabIndex = 11
Top = 4200
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "计 算"
Height = 375
Left = 840
TabIndex = 10
Top = 4200
Width = 1215
End
Begin VB.TextBox Text5
Height = 615
Left = 960
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 9
Top = 3240
Width = 4575
End
Begin VB.TextBox Text4
Height = 615
Left = 960
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 7
Text = "frmVBOLE.frx":0000
Top = 1800
Width = 4575
End
Begin VB.TextBox Text3
Height = 615
Left = 960
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 5
Text = "frmVBOLE.frx":001C
Top = 840
Width = 4575
End
Begin VB.TextBox Text2
Height = 375
Left = 4440
TabIndex = 3
Text = "1"
Top = 240
Width = 1095
End
Begin VB.TextBox Text1
Height = 375
Left = 1560
TabIndex = 1
Text = "8"
Top = 240
Width = 1095
End
Begin VB.Label Label5
Caption = "多项式系数和常数项"
Height = 255
Left = 480
TabIndex = 8
Top = 2760
Width = 1815
End
Begin VB.Label Label4
Caption = "Y"
Height = 375
Left = 480
TabIndex = 6
Top = 1800
Width = 255
End
Begin VB.Label Label3
Caption = "X"
Height = 375
Left = 480
TabIndex = 4
Top = 840
Width = 255
End
Begin VB.Label Label2
Caption = "多项式的阶次"
Height = 255
Left = 3000
TabIndex = 2
Top = 240
Width = 1215
End
Begin VB.Label Label1
Caption = "数据组数"
Height = 255
Left = 480
TabIndex = 0
Top = 240
Width = 855
End
End
Attribute VB_Name = "frmVBOLE"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'将MATLAB实例对象定义为公共变量
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.Text)
intLevel = Val(Text2.Text)
Open App.Path + "/datX" For Output As 1
Print #1, Text3
Close 1
Open App.Path + "/datY" For Output As 1
Print #1, 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
'定义在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)"
Text5 = objMATLAB.execute(strCommand)
Else
strCommand = strCommand & "plot(x,y)"
objMATLAB.execute (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 frmVBOLE
End Sub
Private Sub Form_initialize()
'创建MATLAB的实例
Set objMATLAB = CreateObject("matlab.application")
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -