Extract function/code from MATLAB to c++

2 ビュー (過去 30 日間)
Chris
Chris 2023 年 3 月 9 日
回答済み: Ryan Livingston 2023 年 3 月 11 日
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 Center および File ExchangeMATLAB Coder についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by