%% Example: Control Inlining at the Boundary Between Your Functions and MathWorks® Functions
% This example shows how to control inlining behavior at all call sites where a function that you wrote calls a MathWorks function, or a MathWorks function calls a function that you wrote.
%% Define A Function That Calls MathWorks Functions
% Define a MATLAB function useBessely that accepts a double array x as input, processes the input array by using the bessely function, and returns an array that has the same type and size as x.

type useBessely.m

%% Generate Code With Default Inlining Settings
% Generate a static C++ library for the useBessely function. Specify the input to be a 1-by-100 double type. Use the default values for the inlining settings. These default values optimize the speed of the generated code. Use the -c flag that instructs the code generator to produce source code only and not build the source code.

codegen -c -lang:c++ -config:lib useBessely -args {zeros(1,100)} -report

% Open the code generation report and inspect the generated code. Observe that no separate C++ function has been generated for the MathWorks function bessely. The code generator has inlined the code for the bessely function into the C++ useBessely function that is contained in the file useBessely.cpp.
%% Generate Code With Modified Inlining Settings
% Define a code configuration object cfg for generating a static C++ library. Set the property InlineBetweenUserAndMathWorksFunctions to 'Never'. This setting instructs the code generator to separate the function that you wrote and the MathWorks functions in the generated code. As a result, the generated C++ code is less efficient but more readable than the inlined code.

cfg = coder.config('lib');
cfg.TargetLang = 'C++';
cfg.InlineBetweenUserAndMathWorksFunctions = 'Never';

% Generate code by using cfg as the code configuration object. Specify the input to be a 1-by-100 double type. Use the -c flag that instructs the code generator to produce source code only and not build the source code.

codegen -c -config cfg useBessely -args {zeros(1,100)} -report

% Open the code generation report and inspect the generated code. The C++ function useBessely now calls another C++ function coder::bessely that contains the code generated for the MathWorks function bessely. As a reault, the generated C++ useBessely function looks similar to the MATLAB useBessely function that you wrote.

type codegen/lib/useBessely/useBessely.cpp

% Copyright 2020 The MathWorks, Inc.