1)使用MATLAB引擎 在服务器端开启程序
2)然后输入参数进行运算
3)再获得结果
4)关闭MATLAB引擎
在网上有看到VC++的,但是没有具体的接口信息。
各位施主,有相关MATLAB信息的过来支持下哦。。
EMALL: linqinhui#sohu.com
4 个解决方案
#1
这里有个vb.net的
首先在.NET中,引用matlab 的对象库(Matlab Application(version 6.5) Type Library),笔者采用的是MATLAB 6.5 版本,然后在窗体上加一个图片框PictureBox1,用于显示图片;
一个Button1用于调用MATLAB,并加载图形。
代码:
Dim strMatLab As String '定义matlab语句字符串
' 显示正弦图
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MatLab As Object
'建立matlab应用
MatLab = CreateObject("matlab.application")
'最小化matlab命令窗口
MatLab.MinimizeCommandWindow()
'matlab语句
strMatLab = "t=2:0.2:4*pi;y=sin(t);plot(t,y)"
'执行matlab算法
matlab.Execute(strMatLab)
'生成一个JPG的图形c:\Test1.jpg
matlab.Execute("print( gcf, '-djpeg', 'c:\Test1')")
'退出matlab,释放资源
matlab.Quit()
MatLab = Nothing
'显示在图片框
PictureBox1.Image = New Bitmap("c:\Test1.jpg")
End Sub
' 显示饼图
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "sale=[100 400 150 250 500];pie3(sale,[0 0 1 0 0],{'公司A','公司B','公司C','公司D','公司E'})"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test2')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test2.jpg")
End Sub
' 显示三维螺旋线图
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "t=0:0.2:4*pi;plot3(sin(t),cos(t),t)"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test3')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test3.jpg")
End Sub
' 显示立体波浪图
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "[X,Y,Z] = peaks(20);surfc(X,Y,Z);colormap hsv;axis ([-2 4 -6 8 -10 6])"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test5')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test5.jpg")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
首先在.NET中,引用matlab 的对象库(Matlab Application(version 6.5) Type Library),笔者采用的是MATLAB 6.5 版本,然后在窗体上加一个图片框PictureBox1,用于显示图片;
一个Button1用于调用MATLAB,并加载图形。
代码:
Dim strMatLab As String '定义matlab语句字符串
' 显示正弦图
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MatLab As Object
'建立matlab应用
MatLab = CreateObject("matlab.application")
'最小化matlab命令窗口
MatLab.MinimizeCommandWindow()
'matlab语句
strMatLab = "t=2:0.2:4*pi;y=sin(t);plot(t,y)"
'执行matlab算法
matlab.Execute(strMatLab)
'生成一个JPG的图形c:\Test1.jpg
matlab.Execute("print( gcf, '-djpeg', 'c:\Test1')")
'退出matlab,释放资源
matlab.Quit()
MatLab = Nothing
'显示在图片框
PictureBox1.Image = New Bitmap("c:\Test1.jpg")
End Sub
' 显示饼图
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "sale=[100 400 150 250 500];pie3(sale,[0 0 1 0 0],{'公司A','公司B','公司C','公司D','公司E'})"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test2')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test2.jpg")
End Sub
' 显示三维螺旋线图
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "t=0:0.2:4*pi;plot3(sin(t),cos(t),t)"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test3')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test3.jpg")
End Sub
' 显示立体波浪图
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "[X,Y,Z] = peaks(20);surfc(X,Y,Z);colormap hsv;axis ([-2 4 -6 8 -10 6])"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test5')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test5.jpg")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
#2
也可以考虑直接使用MATLAB server版开发,这个可以直接在web使用
另:如果是这种要求,我可以考虑使用python开发com库,再用asp.net调用,这样服务器就可以脱离matlab这个东东独立运行了python下有很多移植于matlab的库,象matplotlib和pylib等,大多数matlab功能这几个库都可以实现,而且用python开发com也很容易
也可以这样将m文件使用matcom这个东西,编译成com让asp.net调用,这样都可以脱离matlab环境,让服务器减少些负担,毕竟matlab这个东东个头也不小
另:如果是这种要求,我可以考虑使用python开发com库,再用asp.net调用,这样服务器就可以脱离matlab这个东东独立运行了python下有很多移植于matlab的库,象matplotlib和pylib等,大多数matlab功能这几个库都可以实现,而且用python开发com也很容易
也可以这样将m文件使用matcom这个东西,编译成com让asp.net调用,这样都可以脱离matlab环境,让服务器减少些负担,毕竟matlab这个东东个头也不小
#3
学习一下
#4
哈哈 太大意了
我都没有注意到COM 的库里 有 MATLAB 的库文件
我都没有注意到COM 的库里 有 MATLAB 的库文件
#1
这里有个vb.net的
首先在.NET中,引用matlab 的对象库(Matlab Application(version 6.5) Type Library),笔者采用的是MATLAB 6.5 版本,然后在窗体上加一个图片框PictureBox1,用于显示图片;
一个Button1用于调用MATLAB,并加载图形。
代码:
Dim strMatLab As String '定义matlab语句字符串
' 显示正弦图
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MatLab As Object
'建立matlab应用
MatLab = CreateObject("matlab.application")
'最小化matlab命令窗口
MatLab.MinimizeCommandWindow()
'matlab语句
strMatLab = "t=2:0.2:4*pi;y=sin(t);plot(t,y)"
'执行matlab算法
matlab.Execute(strMatLab)
'生成一个JPG的图形c:\Test1.jpg
matlab.Execute("print( gcf, '-djpeg', 'c:\Test1')")
'退出matlab,释放资源
matlab.Quit()
MatLab = Nothing
'显示在图片框
PictureBox1.Image = New Bitmap("c:\Test1.jpg")
End Sub
' 显示饼图
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "sale=[100 400 150 250 500];pie3(sale,[0 0 1 0 0],{'公司A','公司B','公司C','公司D','公司E'})"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test2')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test2.jpg")
End Sub
' 显示三维螺旋线图
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "t=0:0.2:4*pi;plot3(sin(t),cos(t),t)"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test3')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test3.jpg")
End Sub
' 显示立体波浪图
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "[X,Y,Z] = peaks(20);surfc(X,Y,Z);colormap hsv;axis ([-2 4 -6 8 -10 6])"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test5')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test5.jpg")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
首先在.NET中,引用matlab 的对象库(Matlab Application(version 6.5) Type Library),笔者采用的是MATLAB 6.5 版本,然后在窗体上加一个图片框PictureBox1,用于显示图片;
一个Button1用于调用MATLAB,并加载图形。
代码:
Dim strMatLab As String '定义matlab语句字符串
' 显示正弦图
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MatLab As Object
'建立matlab应用
MatLab = CreateObject("matlab.application")
'最小化matlab命令窗口
MatLab.MinimizeCommandWindow()
'matlab语句
strMatLab = "t=2:0.2:4*pi;y=sin(t);plot(t,y)"
'执行matlab算法
matlab.Execute(strMatLab)
'生成一个JPG的图形c:\Test1.jpg
matlab.Execute("print( gcf, '-djpeg', 'c:\Test1')")
'退出matlab,释放资源
matlab.Quit()
MatLab = Nothing
'显示在图片框
PictureBox1.Image = New Bitmap("c:\Test1.jpg")
End Sub
' 显示饼图
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "sale=[100 400 150 250 500];pie3(sale,[0 0 1 0 0],{'公司A','公司B','公司C','公司D','公司E'})"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test2')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test2.jpg")
End Sub
' 显示三维螺旋线图
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "t=0:0.2:4*pi;plot3(sin(t),cos(t),t)"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test3')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test3.jpg")
End Sub
' 显示立体波浪图
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim matlab As Object
matlab = CreateObject("matlab.application")
strMatLab = "[X,Y,Z] = peaks(20);surfc(X,Y,Z);colormap hsv;axis ([-2 4 -6 8 -10 6])"
matlab.Execute(strMatLab)
matlab.Execute("print( gcf, '-djpeg', 'c:\Test5')")
matlab.Quit()
matlab = Nothing
PictureBox1.Image = New Bitmap("c:\Test5.jpg")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
#2
也可以考虑直接使用MATLAB server版开发,这个可以直接在web使用
另:如果是这种要求,我可以考虑使用python开发com库,再用asp.net调用,这样服务器就可以脱离matlab这个东东独立运行了python下有很多移植于matlab的库,象matplotlib和pylib等,大多数matlab功能这几个库都可以实现,而且用python开发com也很容易
也可以这样将m文件使用matcom这个东西,编译成com让asp.net调用,这样都可以脱离matlab环境,让服务器减少些负担,毕竟matlab这个东东个头也不小
另:如果是这种要求,我可以考虑使用python开发com库,再用asp.net调用,这样服务器就可以脱离matlab这个东东独立运行了python下有很多移植于matlab的库,象matplotlib和pylib等,大多数matlab功能这几个库都可以实现,而且用python开发com也很容易
也可以这样将m文件使用matcom这个东西,编译成com让asp.net调用,这样都可以脱离matlab环境,让服务器减少些负担,毕竟matlab这个东东个头也不小
#3
学习一下
#4
哈哈 太大意了
我都没有注意到COM 的库里 有 MATLAB 的库文件
我都没有注意到COM 的库里 有 MATLAB 的库文件