Extract function/code from MATLAB to c++

4 vues (au cours des 30 derniers jours)
Chris
Chris le 9 Mar 2023
I'm using MATLAB to improve/code algorithms. I want to extract some parts , like filters in C++ or library to use on production project.
By example :
classdef FilterXXX < handle
properties (Access = private)
...
end
properties (Access = private, Constant = true)
...
end
methods
function obj = XXX(A,B)
% Constructor
end
function A = YYY
.....
end
end
Here, i want to extract the function A = YYY which is a algorithm or almost the entire class. I try to use MATLAB Coder, but seems i cant give a class to improve the conversion. The entrypoint need to be a function.To perform this action of converting MATLAB Code on libraries/C++. Do I need to make any changes to my code, for example this class in a function I would create to use MATLAB Coder or am I missing something

Réponses (1)

Ryan Livingston
Ryan Livingston le 11 Mar 2023
A workaround for this case is to use a wrapper function
function A = FilterXXXWrapper(in1,in2,in3,in4)
% Construct your object
obj = FilterXXX(in1,in2);
% Use your object to do the desired computations
A = obj.YYY(in3,in4);
end
If you need to accumulate state in your object across multiple calls then store it in a persistent variable in your entry-point function
function A = FilterXXXWrapper(in1,in2,in3,in4)
persistent obj;
if isempty(obj)
% Construct your object
obj = FilterXXX(in1,in2);
end
% Use your object to do the desired computations
A = obj.YYY(in3,in4);
end

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by