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
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!