How to get the return value of a compiled m-function?

6 views (last 30 days)
Hi everyone,
I am working with genetic algorithms in MATLAB. In my fitness function I call another MATLAB function called 'model', that takes several seconds to execute (about 45s).
In order to speed-up things a little bit I've compiled the model
mcc -N -m model
Of course I've adapted the model.m function in order to deal with string parameters.
Then, in order to pass a vector to the function, I prepare a command string like this:
cmd = 'model [1 2 3 4]';
and call
eval(cmd)
So far so good. The problem is: how to get the return value of the function (that is a matrix)? I can see the numerical output in the 'ans' variable after calling eval, so the output is produced correctly.
I've tried with this syntax:
output = eval(cmd)
but this generates a syntax error, given that the resulting command is something like:
output = model [1 2 3 4]
given that after eval(cmd) I have the correct numerical value in 'ans', I've found this workaround:
eval(cmd) output = ans;
but I think this is not very elegant, nor safe. Moreover, my application is parallelized, so I don't feel very comfortable using 'ans' in this way (am I right?).
If you share my doubts about this solution, could you please suggest me a better way to get the output value of a compiled m-function being called inside matlab?
Thank you very much
Best regards

Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!