基于VB平台的simulink电力继电保护仿真
正在做一个毕设,在vb界面上显示Simulink的仿真模型且可在VB界面上修改仿真参数,下面是部分代码,求助大神帮看看,是在搞不懂Option Explicit
Public Matlab As Object
Dim mreal(0, O) As Double
Dim minnag(0, 0) As Double
Private Sub Form_Initialize()
Set Matlab = CreateObject("matlab.application")
End Sub
'创建MATLAB的实例,初始化以及定义变量
Private Sub Commandl_Click()
'按下Command按钮后
Call Matlab.putfullmatrix("b", "base", mreal, mimag)
'将VB中数据传入Matlab的workspace中
Matlab.execute ("sim C:\Users\Administrator\Desktop\shiyan1.mdl")
'运行距离保护Simulink模型
Private Sub Form_Load()
Text3.Text = 0.2 'Text3为仿真时间
End Sub
Private Sub Image2_DblClick()
End Sub
L1参数.Show
End Sub
Private Sub Image3_DblClick()
L2参数.Show
End Sub
Private Sub Image4_DblClick()
L2参数.Show
End Sub
'三个子窗体,在线路上双击来修改三段线路参数
Private Sub Text3_Change()
mreal(0, 0) = Text3.Text
End Sub
Private Sub Command1_Click()
Call Matlab.putfullmatrix("b", "base", mreal, mimag)
'将VB中的数据传入Matlab的workspace中
Matlab.execute ("C:\Users\Administrator\Desktop\shiyan1.mdl")
'需要先仿真一遍才能修改参数
Matlab.execute ("set_param('shiyan1','stoptime','b(:,1))")
'设置仿真时间
Matlab.execute ("sim C:\Users\Administrator\Desktop\shiyan1.mdl")
If Check1.Value = 1 Then
Matlab.execute ("set_param(shiyan1/Three-Phase Fault','faultA','on)")
Else
Matlab.execute ("set_param(shiyan1/Three-Phase Fault','faultA','off)")
End If
If Check2.Value = 1 Then
Matlab.execute ("set_param(shiyan1/Three-Phase Fault','faultB','on)")
Else
Matlab.execute ("set_param(shiyan1/Three-Phase Fault','faultB','Off)")
If Check3.Value = 1 Then
Matlab.execute ("set_param(shiyan1/Three-Phase Fault','faultC','on)")
Else
Matlab.execute ("set_param(shiyan1/Three-Phase Fault','faultC','Off)")
End If
'以上代码用来设置短路类型(单相或者多相)
Matlab.execute ("sim shiyan1.mdl") '仿真
Matlab.execute ("run shiyan1") 'Maflab编程
Maflab.execute ("print-f3-dmeta")
Picture1.Picture = Clipboard.GetData
Matlab.execute ("print-f1-dmeta")
Picture2.Picture = Clipboard.GetData
Madab.execute ("print-f2一dmeta")
Picture3.Picture = Clipboard.GetData
End Sub
'以上代码为从Matlab中取出仿真结果图