jyws89 has asked for the wisdom of the Perl Monks concerning the following question:

Dear gurus and masters, some help needed here

I'm actually on a project for my Final Year Project, basically my task now is to link a simple matlab algorithm to my web server.

First, I started up by setting a personal web server following this link

http://lifehacker.com/124212/geek-to-live-...home-web-server

After configuring apache to run CGI, and all that....It works well and I even setup a static IP for it so it can be access remotely,

Then, I starting to make some linking according to this

http://www.mathworks.com/support/solutions/en/data/1-30REEY/

which is to deploy a magicsquare (assigning numbers 1~9, if 3x3 is selected so that all numbers had the same sum when added vertically) matlab application to webserver, I followed all the steps there and it works well too smile.gif I can send the number of array for the magicsquare(enter 3) and get processed by matlab's mcr, getting a response from it (a well-assigned magicsquare).

I've tried accessing the m-files inside the mcr, but all the characters are vexed and distorted.

The Problem now is : I had no idea what is actually running, which/what CGI script is actually used to link both my web server and matlab. I was wondering if someone can help me out here by telling me how to link web server and matlab so that i actually understands. For now i believe using writing CGI script to call matlab for processing is the way but i'm very very newbie on this field. Desperate help needed cry.gif

my supervisor assigned me to do a simple A+B application, as in you can enter the value of A and B, click on calculate, and matlab will process the answer out and return back the value to display at my web server. Flow = enter A and B in webserver > cgi calls up to matlab to process > matlab passing back result to cgi> cgi pass result to webserver> display on webserver

Do let me know if my explanation is blur, thx!

  • Comment on Linking Matlab to process data for Personal Web Server

Replies are listed 'Best First'.
Re: Linking Matlab to process data for Personal Web Server
by poj (Abbot) on Dec 12, 2010 at 19:14 UTC

    From what I can see the standalone.html is a static html page that displays an input box and a button thus

    <HTML> <BODY> <FORM ACTION="/cgi-bin/mycgimagic.exe"> <P>Please specify the size: <INPUT NAME="size" SIZE="5"><BR> <INPUT TYPE="SUBMIT" VALUE="Go!"> </FORM> </BODY> </HTML>

    When you press the button on the page, the request sent to the webserver is to execute the program /cgi-bin/mycgimagic.exe which is the compiled version of mycgimagic.m.

    Using the size parameter extracted from the environment variable QUERY_STRING, the program computes the magic square and the response received by your browser is an html page created using the fprint(1,text) statements withing the program starting with this one

    fprintf(1,'Content-type: text/html\n');

    and later these

    function createTable(M) s = size(M); fprintf(1,'<table border = "2">'); for i=1:s(1) fprintf(1,' <tr>'); for j=1:s(2) fprintf(1,[' <td>',num2str(M(i,j),'%4.2f'),'</td>']); end fprintf(1,' </tr>'); end

    hope that helps a bit

    poj

      Thx for the reply and sorry for being late in replying back, i admit that i'm stupid enough that I actually didn't open up the mycgimagic.m file and have a look to it's content.

      Anyway, I am now creating a new algorithm, which is to calculate the square of a number (power of 2) by modeling to the sample m.file given in mycgimagic.m, I somehow stuck halfway and I can't pass back my result entirely, only the header is showing back. here is the coding

      function firstdeploy() input = (getenv('QUERY_STRING')); printHeader() x=str2double(input.size); sqre(x); printContent() printFooter() end function sqre = sqre(x) sqre = (x^2); end function printHeader() fprintf(1,'Content-type: text/html\n'); fprintf(1,'\n'); %Print the HTML response page to STDOUT. fprintf(1,'<HTML>'); fprintf(1,'<HEAD><TITLE>My Squaring</TITLE></HEAD>'); fprintf(1,'<BODY>'); end function printContent() fprintf(1,'<P>This is the square of your input:</P>'); fprintf(1, sqre(x)); end function printFooter() fprintf(1,'</BODY>'); fprintf(1,'</HTML>\n'); end

      I hope that any guru and masters here can point out my mistakes, I'm still very new to programming, willing to learn more about it. Sorry for any inconvenience caused

        You need to process the QUERY_STRING with the function qs2struct

        input = qs2struct(getenv('QUERY_STRING'));

        and to check it is working I would add these lines to printContent()

        fprintf(1,'<P>This is your input:</P>'); fprintf(1, x);
        poj