matlab server and user defined matlab functions ...

MATLAB interface, C API, using plugins, other interfaces

Re: matlab server and user defined matlab functions ...

Postby jjkparker » Wed Jul 11, 2012 6:47 pm

I see the timeout. I have this GMAT script:

Code: Select all
Create Variable n ret
Create MatlabFunction myfunc
Create ReportFile r

BeginMissionSequence

n = 100000000000
[ret] = myfunc(n)
Report r ret

and this MATLAB function:

Code: Select all
function out = myfunc(x)

for i=1:x
    continue
end

out = x;

end


MATLAB takes 263 seconds to with this input, while GMAT is less than 10 seconds.
Joel J. K. Parker
Flight dynamics engineer, GMAT team
http://gmatcentral.org
jjkparker
 
Posts: 617
Joined: Thu Jan 07, 2010 9:48 pm
Location: NASA Goddard Space Flight Center, Greenbelt, MD

Re: matlab server and user defined matlab functions ...

Postby jjkparker » Wed Jul 11, 2012 7:02 pm

GMT-2923 is the timeout issue.

I think the addpath issues are caused by the fact that when called from GMAT, pwd returns the path to the MATLAB install directory. As a matter of interest, I think if you changed this code:
Code: Select all
cdir = pwd;
addpath(genpath(cdir));

to this:
Code: Select all
cdir = fileparts(mfilename('fullpath'));
addpath(genpath(cdir));

it would work fine (and be working-dir agnostic in general).
Joel J. K. Parker
Flight dynamics engineer, GMAT team
http://gmatcentral.org
jjkparker
 
Posts: 617
Joined: Thu Jan 07, 2010 9:48 pm
Location: NASA Goddard Space Flight Center, Greenbelt, MD

Re: matlab server and user defined matlab functions ...

Postby marchand » Wed Jul 11, 2012 7:29 pm

Joel,

I changed yourfunction loop to this and that works for me:

Code: Select all
function out = myfunc(x)

out = x;
for i=1:x
    out = sqrt(i);
   disp([' i = ', num2str(i),' out = ',num2str(out)]);
    continue
end

end


It doesn't seem to time out for me this way. Something definitely strange was going on with your original version, though I'm not sure what it was. Before I made the changes above, I added a line at the end of the file that said out = sqrt(x/1e5), and that seemed to be returned properly to GMAT because the report file said 1000 as expected, even though the function ran way too fast to expect anything to be correct. It's almost as if it the matlab engine skipped the loop altogether when there were no mathematical operations within it.

--B.



jjkparker wrote:I see the timeout. I have this GMAT script:

Code: Select all
Create Variable n ret
Create MatlabFunction myfunc
Create ReportFile r

BeginMissionSequence

n = 100000000000
[ret] = myfunc(n)
Report r ret

and this MATLAB function:

Code: Select all
function out = myfunc(x)

for i=1:x
    continue
end

out = x;

end


MATLAB takes 263 seconds to with this input, while GMAT is less than 10 seconds.
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm

Re: matlab server and user defined matlab functions ...

Postby jjkparker » Wed Jul 11, 2012 9:14 pm

Interesting, thanks for the info. I'll point the bug I checked in back to this.
Joel J. K. Parker
Flight dynamics engineer, GMAT team
http://gmatcentral.org
jjkparker
 
Posts: 617
Joined: Thu Jan 07, 2010 9:48 pm
Location: NASA Goddard Space Flight Center, Greenbelt, MD

Re: matlab server and user defined matlab functions ...

Postby marchand » Wed Jul 11, 2012 9:14 pm

You're awesome! That worked, and I was able to fix the problems with Matlab's fprintf command by specifying the full path to the files in a similar way. Basically, instead of defining the filename as:

Code: Select all
fname = 'output';


I now do this

Code: Select all
fname=strcat(cdir,filesep,'output');


The save command is *almost* working with a similar arrangement, except now I get some permission error when I try to save it which I have not yet tracked down completely. The permission error only comes up when I run the code from GMAT, it doesn't come up if I run it from matlab directly. I can find a way around it though, since fprintf is working.

Thanks!


jjkparker wrote:GMT-2923 is the timeout issue.

I think the addpath issues are caused by the fact that when called from GMAT, pwd returns the path to the MATLAB install directory. As a matter of interest, I think if you changed this code:
Code: Select all
cdir = pwd;
addpath(genpath(cdir));

to this:
Code: Select all
cdir = fileparts(mfilename('fullpath'));
addpath(genpath(cdir));

it would work fine (and be working-dir agnostic in general).
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm

Previous

Return to External Interfaces and Plugins

Who is online

Users browsing this forum: No registered users and 1 guest