Using Matlab Coder on script which calls several functions

2 views (last 30 days)
Hello,
I have a question using Matlab Coder.
I have a .m file I would like to convert. Schematically it's like such:
[a,b,c] = function1(e,f,g);
.
.
calculations
.
.
call to matlab function2;
call to matlab function3;
.
.
calculations
.
.
end
I would like to know how to, or whether it's possible, to just convert the actual script function1, and not the functions it calls, merely to pass the information calculated in the script to the other matlab functions2 and 3, without converting them (mainly because it would be a real headache).
Cheers,
Francesco

Accepted Answer

Ryan Livingston
Ryan Livingston on 9 Nov 2014
Are you generating a MEX function? If not, i.e. you are generating standalone code, then you'll need to provide some replacements for function2, function3.
Assuming you are generating a MEX function, one suggestion could be to refactor function1 so that the "calculations" are in separate functions. Generate MEX functions for those new calculation functions and call the generated MEX from function1:
function [a,b,c] = function1(d,e,f)
[x,y,z] = calculation1_mex(d,e,f);
call to function1
call to function2
calculation2_mex(d,e,f);
Alternatively, you could consider declaring function2 and function3 as extrinsic functions:
function [a,b,c] = function1(d,e,f)
coder.extrinsic('function1','function2');
calculations
call to function1
call to function2
calculations
You can see the doc link above for a description of how to access the outputs, if any, from these functions. The general idea is to assign the output before the call:
% Update the size, complexity and
% data type to match what function1
% returns
y = zeros(10,12);
y = function1(...);

More Answers (0)

Categories

Find more on MATLAB Coder 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!