执行Matlab命令

用VBScript来控制MATLAB的尝试  

Set matlab=WScript.CreateObject("Matlab.Application")

matlab.visible=false
matlab.execute("t=0:0.1:2*pi;y=sin(t);plot(t,y)")
matlab.execute("pause(5)")
matlab.quit

上面的程序就是最简单的控制MATLAB了,就是画一条正弦曲线。然后自动退出MATLAB。看起来,也还可以了。以后有什么新想法的话,再往深里面编写。

另外,可用的函数有:

Execute

Execute MATLAB command in server

Feval

Evaluate MATLAB command in server

GetCharArray

Get character array from server

GetFullMatrix

Get matrix from server

GetWorkspaceData

Get any type of data from server

PutCharArray

Store character array in server

PutFullMatrix

Store matrix in server

PutWorkspaceData

Store any type of data in server

MaximizeCommandWindow

Display server window on Windows? desktop

MinimizeCommandWindow

Minimize size of server window

Quit

Quit the MATLAB session

delete

Terminate MATLAB server process

用VBScript控制MATLAB 

将下面的代码存为一个htm文件的源文件,就可以了。然后不用打开MATLAB就可以输入MATLAB语句了。

具体代码:

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>执行Matlab命令</title>

</head>

<body>

<script language=vbscript>
dim Matlab
dim plottext
set Matlab=CreateObject("Matlab.Application")
Matlab.Visible=false
</script>

<Form name="matlabform">
<p>Matlab命令:<br>
<textarea rows="11" name="plotcmd" cols="94"></textarea><br><br>
<input type="button" name="matlabplot" value="执行" >&nbsp;
<script FOR="matlabplot" EVENT="onClick" language =vbscript >
dim doc
dim wksvar
set doc=Document.matlabform
plottext=doc.plotcmd.value
Matlab.execute(plottext)
</script>
<input type="button" name="clearcmd" value="清空" >&nbsp;
<script FOR="clearcmd" EVENT="onClick" language =vbscript >
dim doc
set doc=Document.matlabform
doc.plotcmd.value=""
</script>
<input type=button value ="退出MATLAB" name="quitmatlab">
<script FOR="quitmatlab" EVENT ="onClick" language =vbscript >
Matlab.Quit
MsgBox("已经退出MATLAB了。")
</script>
<input type=button value="打开MATLAB" name="openmatlab">
<script FOR=openmatlab event=onclick language=vbscript>
dim Matlab
set Matlab=CreateObject("Matlab.Application")
MsgBox("已经打开MATLAB了。")
</script>
</p>
</Form>
</body>

</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值