How do I modify object arrays to support C/C++ code generation?

6 views (last 30 days)
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!
Image = imread('someImg.jpg');
myClassArray = detectORBFeatures(Image); % myClassArray is ORBPoints arrays
if"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!
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
cui on 26 Oct 2022
This problem can be solved and may not be an optimal solution is write a function in terms of object arrays, NOT USING CELL ARRAYS THAT REFER TO DOCUMENTION.
function dstORBPoints = getSubInds(srcORBPoints,validIdxs)
Location = srcORBPoints.Location(validIdxs,:);
Metric = srcORBPoints.Metric(validIdxs);
Scale = srcORBPoints.Scale(validIdxs);
Orientation = srcORBPoints.Orientation(validIdxs);
dstORBPoints = ORBPoints(Location,"Metric",Metric,"Orientation",Orientation,"Scale",Scale);

Sign in to comment.

Answers (0)


Find more on Generating Code 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!