题目:在Linux下的MATLAB中运行MATLAB程序并在web中显示结果
我做了一个例子主要有5个文件:
webtttt.html webtttt1.html webtttt2.html webtttttempt.html webttttrnd.m
1.webtttt1.html文件
<!-- $Revision: 1.2 $ -->
<HTML>
<HEAD>
<TITLE>Simulation of Future Stock Prices</TITLE>
</HEAD>
<frameset cols="40%, *" border=0>//将首页分为两个界面
<frame scrolling=auto
src="webtttt.html" //左面调用webtttt.html
name="leftframe"
marginwidth=10
marginheight=1
frameborder=0>
<frame scrolling=auto
src="webtttttemp.html" //右面调用webtttttempt.html
marginwidth=0 marginheight=0
name="outputwindow" frameborder=0>
</frameset>
</body>
</HTML>
2.webtttt.html //左边的一部分
<!-- $Revision: 1.2 $ -->
<html>
<head>
<title>test</title>
</head>
<body bgcolor="#FFFFFF">
<div align="center"><font color="#000000" size="4" face="Arial">
<i>choose or input signal</i></font></div>
<form action="/cgi-bin/matweb" method="POST" target="outputwindow">
<input type="hidden" name="mlmfile" value="webttttrnd">
<table border="2">
<tr>
<td width="140" align="right">
信号1 : </td>
<td width="161" align="left">
<select name="signalone" id="signalone">
<option value="door">Door</option>
<option value="triangle">Triangle</option>
<option value="3">ttttttttttt</option>
</select> </td>
</tr>
<tr >
<td colspan="2" align="center">
<input type="text" align="middle" size = "20" value="rectpuls(t,2)" name="oneval"> </td>
</tr>
<tr>
<td height="30" align="right">
信号2 : </td>
<td>
<select name="signaltwo" id="signaltwo">
<option value="door">Door</option>
<option value="triangle">Triangle</option>
<option value="13">ttttttttttt </option>
</select> </td>
</tr>
<tr>
<td height="28" colspan="2" align="center"><input type="text" size = "20" value="tripuls(t,1)" name="twoval"></td>
</tr>
<tr>
<td height="33" align="right">
时间下限 : </td>
<td align="left">
<input type="text" size = "10" value="-2" name="time1"> </td>
</tr>
<tr>
<td height="33" align="right">
时间上限 : </td>
<td align="left">
<input type="text" size = "10" value="2" name="time2"> </td>
</tr>
<tr>
<td height="33" align="right">
平移 b : </td>
<td>
<input type="text" size = "10" value="2" name="moving"> </td>
</tr>
<tr>
<td height="33" align="right">
尺度变换 a : </td>
<td>
<input type="text" size = "10" value="2" name="change"> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="显示波形"> </td>
</tr>
</table>
<br>
<table>
<tr>
<td width="145">
<div align="right">
<input type="submit" name="Submit" value="f1(t)+f2(t)">
</div></td>
<td width="166">
<input type="submit" name="Submit" value="f1(t)-f2(t)"> </td>
</tr>
<tr></tr>
<tr>
<td>
<div align="right">
<input type="submit" name="Submit" value="f1(t)f2(t)">
</div></td>
<td>
<input type="submit" name="Submit" value="f1(t-b)"> </td>
</tr>
<tr></tr>
<tr>
<td>
<div align="right">
<input type="submit" name="Submit" value="f1(-t)">
</div></td>
<td>
<input type="submit" name="Submit" value="f1(at)"> </td>
</tr>
<tr></tr>
<tr>
<td>
<div align="right">
<input size="20" type="submit" name="Submit" value="f1(at-b)">
</div></td>
<td>
<input size="80" type="submit" name="Submit" value="奇偶分量"> </td>
</tr>
</table>
</form>
</body>
</html>
3 webtttttempt.html //右边部分
<!-- $Revision: 1.1 $ -->
<html>
<body bgcolor=#FFFFFF>
</body>
</html>
1,2,3生成的界面为:
4.webttttrnd.m //写matlab程序,生成图片保存在指定文件中
function PageString=webttttrnd(InputSet, OutFile)
cd(InputSet.mldir);
wscleanup('wsrml*.jpeg', 1);
%functname1=InputSet.signalone;
%functname2=InputSet.signaltwo;
functname3=InputSet.Submit;
t0=str2double(InputSet.time1);
t1=str2double(InputSet.time2);
b=str2double(InputSet.moving);
a=str2double(InputSet.change);
global signal1;
signal1=InputSet.oneval;
signal2=InputSet.twoval;
dt=0.02;
t=-100:dt:100;
y1=eval(signal1);
Fig = figure('visible','off');
subplot(3,2,[1,2]);
max_y=max(y1);min_y=min(y1);
plot(t,y1,'linewidth',2);grid;dy=0.2;
axis([t0,t1,min_y-dy,max_y+dy]);
title('信号显示');
set(gca,'FontSize',8);
%myplot(t,y1);
y2=eval(signal2);
subplot(3,2,[3,4]);
max_y=max(y2);min_y=min(y2);dy=0.2;
plot(t,y2,'linewidth',2);grid;
axis([t0,t1,min_y-dy,max_y+dy]);
set(gca,'FontSize',8);
if(strcmp(functname3,'f1(t)+f2(t)'))
y3=y1+y2;
elseif(strcmp(functname3,'f1(t)-f2(t)'))
y3=y1-y2;
elseif(strcmp(functname3,'f1(t)f2(t)'))
y3=y1.*y2;;
elseif(strcmp(functname3,'f1(t-b)'))
y3=zdyf(t-b);
elseif(strcmp(functname3,'f1(-t)'))
y3=zdyf(-t);
elseif(strcmp(functname3,'f1(at)'))
y3=zdyf(a.*t);
elseif(strcmp(functname3,'f1(at-b)'))
y3=zdyf(a.*t-b);
elseif(strcmp(functname3,'奇偶分量'))
f1=zdyf(t);
f2=zdyf(-t);
y3=(f1+f2)/2;
y4=(f1-f2)/2;
else
end
if(exist('y3') & exist('y4')==0)
subplot(3,2,[5,6]);
max_y=max(y3);min_y=min(y3);dy=0.2;
plot(t,y3,'linewidth',2);grid;
axis([t0,t1,min_y-dy,max_y+dy]);
set(gca,'FontSize',8);
elseif(exist('y3') & exist('y4'))
subplot(3,2,5);
max_y=max(y3);min_y=min(y3);dy=0.2;
plot(t,y3,'linewidth',2);grid;
axis([t0,t1,min_y-dy,max_y+dy]);
set(gca,'FontSize',8);
subplot(3,2,6);
max_y=max(y4);min_y=min(y4);dy=0.2;
plot(t,y4,'linewidth',2);grid;
axis([t0,t1,min_y-dy,max_y+dy]);
set(gca,'FontSize',8);
else
end
PlotFile = sprintf('wsr%s.jpeg', InputSet.mlid);
drawnow;
wsprintjpeg(Fig, PlotFile);
close(Fig);
templatefile = which('webtttt2.html');
if ( exist('OutFile','var') == 1 )
% write Page to a diagnosticile
s.GraphFileName = [ PlotFile];
PageString = htmlrep(s, templatefile, OutFile);
else
s.GraphFileName = ['/icons/' PlotFile];
PageString = htmlrep(s, '/usr/src/matlab/toolbox/webserver/wsdemos/webtttt2.html');
end
function y=zdyf(t)
global signal1;
y=eval(signal1);
5 webtttt2.html
<!-- $Revision: 1.1 $ -->
<html>
<body bgcolor="#FFFFFF">
<p> </p>
<p align="center">
<img border=0 src="$GraphFileName$">//通过$GraphFileName调用图片
</p>
</body>
</html>
注意:
1:webtttt.html webtttt1.html webtttttempt.html 这三个文件必须放在web的根目录下
webtttt2.html webttttrnd.m这两个文件放在Linux下<matlab>/toolbox/webserver/wsdemos/下;
2:matweb和matweb.conf必须放在/usr/loacal/apache/cgi-bin里
3:当增加.m文件时,matweb.conf新增一项,例如:
[webttttrnd]
mlserver=10.10.19.240
mldir=/usr/src/matlab/toolbox/webserver/wsdemos/icons
4:当出现connect fail();有可能matweb.conf未改;或为启动matlabwebserver;可手动启动
进入matlab下的webserver执行webtart(./start)
5:当出现Error using ==> feval Undefined command/function 'webttttrnd' 可以赋755的权限给webttttrnd.m
在确实解决不了,可重装一个Linux系统在其中装matlab后在试试(本人就是遇到这个问题搞了几天都没解决,最后重装了linux再在其中装matlab再在其中试居然成功了)