in reply to Re: Linking Matlab to process data for Personal Web Server
in thread Linking Matlab to process data for Personal Web Server

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

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

    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

      I check qs2struct with matlab's help and it doesn't seems to be a matlab function...? anyway, i'm studying what actually is the qs2struct function really is. I'll let you know the verdict soon. Thanks for helping out!

        It is in the mycgimagic.m file at the end

        function x=qs2struct(qs) % return the query string as a structure % each field is a paramter name % the value of the field is its value as a string % an example query string: % myinput=test&size=2&num=10 % get the indeces of the characters that divide names and fields div = [0,strfind(qs,'&'),length(qs)+1]; eq = strfind(qs,'='); x.querystring = qs; for i=1:length(eq) field = qs(div(i)+1:eq(i)-1); %field string value = qs(eq(i)+1:div(i+1)-1); %value stirng x = setfield(x,field,value); %place in structure end
        poj