How do I modify object arrays to support C/C++ code generation?
Show older comments
I want to remove some indexed subscript elements in object arrays, where the element type in arrays is matlab built-in ORBPoints type, it is very easy to delete these indexed elements in MATLAB environment, and then when I am ready to generate C code, I found that object arrays is not supported to generate.
I checked the relevant documentation in detail and tried hard to convert object arrays to cell arrays, but it was not easy to convert each ORBPoints to cell arrays.
Any help would be greatly appreciate!
Pseudocode:
Image = imread('someImg.jpg');
myClassArray = detectORBFeatures(Image); % myClassArray is ORBPoints arrays
if coder.target("MATLAB") % MATLAB environment is easy to remove some elements
myClassArray(removeIdxs) = [];
else % Code generation does not support object arrays, so convert to cell arrays
n = numel(myClassArray);
points1Cell = cell(1,n);
for i = 1:n
points1Cell{i} = ORBPoints(...) ? % Constructing ORBPoints using the constructor is not easy, the object has many more properties that also have to be copied all according to the same properties as the elements in myClass! It's a pain!
end
end
Most of the official documentation examples are numeric type to cell arrays conversions, which are relatively simple and easy to follow, but when it comes to types that are not easy to construct, it can be tricky. I have also tried the mat2cell function, but unfortunately this built-in function does not support C/C++ code generation!
1 Comment
xingxingcui
on 26 Oct 2022
Answers (0)
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!