linux下matlab的一个例子

题目:在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>

 

 

 

 

 

 

 

 

 

 

 

 

 

123生成的界面为:

 

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>&nbsp</p>

<p align="center">

<img border=0 src="$GraphFileName$">//通过$GraphFileName调用图片

</p>

</body>

</html>

 

 

注意:

1webtttt.html  webtttt1.html  webtttttempt.html  这三个文件必须放在web的根目录下

webtttt2.html  webttttrnd.m这两个文件放在Linux<matlab>/toolbox/webserver/wsdemos/下;

2matwebmatweb.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再在其中试居然成功了)

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值