weilinmar 发表于 2006-6-2 23:27

[求助]vb调用matlab,如何不出现matlab的图形窗

我在用VB调用MATLAB程序时,代码如下:
Private Sub Command1_Click()
Dim Matlab As Object
Dim result As String
Set Matlab = CreateObject("Matlab.application")

result = Matlab.execute("t=1:5;y=cos(t);plot(t,y)")

result = Matlab.execute("print-dbitmap")
Image1.Picture = Clipboard.GetData()
End Sub

我想问下怎样才能运行时不出现matlab的图形窗

另外
vb调用matlab,如何使用GetFullMatrix。

assist 发表于 2006-6-2 23:36

在matlab 里面设置,查看figure命令
,做相应的处理

ericlin 发表于 2006-6-4 18:17

怎么样,问题解决了吗?如果解决了也请告诉大家哦。^_^

bainhome 发表于 2006-6-5 00:15

MY WAY:
Private Sub cmdDraw_Click()
Dim objMATLAB As Object
Set objMATLAB = CreateObject("matlab.application")
Dim strEnter As String
Dim strCommand As String
strEnter = Chr(13) & Chr(10)
strCommand = "=peaks(30);"
strCommand = strCommand & strEnter
strCommand = strCommand & "surfc(x,y,z)"
strCommand = strCommand & strEnter
strCommand = strCommand & "shading interp"
strCommand = strCommand & strEnter
strCommand = strCommand & "saveas(gcf,'c:\temp.bmp')"
objMATLAB.execute (strCommand)
imgDraw.Picture = LoadPicture("C:\temp.bmp")
imgDraw.Refresh
Set objMATLAB = Nothing
End Sub

mhl516 发表于 2006-6-6 16:36

<P>请问一下 ,在vb中引用哪个才能和matlab 连接啊 /<BR></P>

mxz2006 发表于 2006-6-14 12:18

有个将窗口最小化的函数,不知能不能达到你想要的结果,网上有下载的

anzi_upc 发表于 2006-6-15 09:32

Private Sub Command1_Click()
Dim Matlab As Object
Dim result As String
Set Matlab = CreateObject("Matlab.application")
result = Matlab.execute("figure('visible', 'off')")
result = Matlab.execute("t=1:5;y=cos(t);plot(t,y)")

result = Matlab.execute("print-dmeta")
Image1.Picture = Clipboard.GetData()
End Sub

不知行不行?

xuebx 发表于 2006-6-15 09:45

解决了一个难题,大家积极发言阿

WWLLXX2001 发表于 2006-11-7 14:46

怎样才能运行时不出现matlab的图形窗?

WWLLXX2001 发表于 2006-11-7 14:51

按bainhome的方法,可以把图绘入vb窗口,但有matlab的图形窗出现
用figure('visible','off')好像不行

jimin 发表于 2006-11-7 15:05

原帖由 WWLLXX2001 于 2006-11-7 14:51 发表
按bainhome的方法,可以把图绘入vb窗口,但有matlab的图形窗出现
用figure('visible','off')好像不行
来个抛砖引玉
董维国老师所写的深入浅出matlab7.x混合编程中有一节是介绍
7.42 在mfc应用程序中隐藏matlab的figure窗口
我想vb vc应该类似
看能不能从中找找思路,然后应用到vb中

WWLLXX2001 发表于 2006-11-7 16:50

我用如下方法可以使figure窗口关掉,缺点是figure窗口还是会闪一下
Public Class Form1
    Private Sub cmdDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDraw.Click
      Dim objMATLAB As Object
      objMATLAB = CreateObject("matlab.application")
      Dim strEnter As String
      Dim strCommand As String
      strEnter = Chr(13) & Chr(10)
      strCommand = "=peaks(30);"
      strCommand = strCommand & strEnter
      strCommand = strCommand & "surfc(x,y,z);"
      strCommand = strCommand & strEnter
      strCommand = strCommand & "shading interp;"
      strCommand = strCommand & strEnter
      strCommand = strCommand & "saveas(gcf,'c:\temp.bmp');"
      strCommand = strCommand & strEnter
      strCommand = strCommand & "close(1)"
      objMATLAB.execute(strCommand)   
      imgDraw.Image = Image.FromFile("C:\temp.bmp")
      imgDraw.Refresh()
      objMATLAB = Nothing

    End Sub
End Class

jimin 发表于 2006-11-8 11:32

把我改的拿出来和大家分享一下,大家可以测试一下
Private Sub Command1_Click()
Dim objMATLAB As Object
Set objMATLAB = CreateObject("matlab.application")
Dim strEnter As String
Dim strCommand As String
strEnter = Chr(13) & Chr(10)
strCommand = "figure('visible', 'off', 'Units','points','PaperUnits', 'points');"
strCommand = strCommand & strEnter
strCommand = strCommand & "surf(peaks(25));"
strCommand = strCommand & strEnter
strCommand = strCommand & "print -dmeta"
strCommand = strCommand & strEnter
strCommand = strCommand & "close(gcf)"
strCommand = strCommand & strEnter
objMATLAB.execute (strCommand)
imgDraw.Picture = Clipboard.GetData()
imgDraw.Refresh
Set objMATLAB = Nothing
End Sub

jimin 发表于 2006-11-8 11:38

to   
WWLLXX2001
你的程序我好象运行不了,不知道问题出在什么地方
Public Class Form1
    Private Sub cmdDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDraw.Click
这几句不大懂,能否解释一下

WWLLXX2001 发表于 2006-11-8 16:14

我用的是visual basic 2005
在vb6.0里是运行不了的
页: [1] 2
查看完整版本: [求助]vb调用matlab,如何不出现matlab的图形窗