Extract function/code from MATLAB to c++
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ryan Livingston
am 11 Mär. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!