Extract function/code from MATLAB to c++

2 次查看(过去 30 天)
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

回答(1 个)

Ryan Livingston
Ryan Livingston 2023-3-11
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

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by