Codegen for Bundle Adjustment

I am facing two issues when using codegen on my code. I have attached images of my code for reference.
1) The error report recognises cameraPoses as a struct even though it is a 2x2 table when I run the code. When I take the values in cameraPoses and make camPoses (as shown in the image), that is recognised as a table.
2) Once I use camPoses in Bundle Adjustment, I get a codegen error that says 'This function does not support one-dimensional indexing. I am not sure what that means because my variable dimensions match the documentation. I have also attached images of my variables and their dimensions.

 Accepted Answer

Matt
Matt on 16 Jul 2026
Edited: Matt on 16 Jul 2026
The issue is not your runtime dimensions. Instead, tt is a codegen representation/type issue.
In MATLAB R2026a, the codegen implementation of imageviewset/poses returns a struct:
struct('ViewId', viewsId, 'AbsolutePose', absPoses)
So the report calling "cameraPoses" a struct is expected, even though normal MATLAB execution shows a 2x2 table.
cameraPoses = poses(vSetKeyFrames);
viewIds = uint32(cameraPoses.ViewId(:));
numViews = numel(viewIds);
absolutePose = cell(numViews, 1);
for k = 1:numViews
absolutePose{k} = cameraPoses.AbsolutePose(k);
end
camPoses = table(viewIds, absolutePose, ...
'VariableNames', {'ViewId', 'AbsolutePose'});
[refinedPoints, refinedAbsPoses] = bundleAdjustment( ...
xyzWorldPoints, tracks, camPoses, intrinsics, ...
'FixedViewIDs', uint32(1), BAParams.full{:});
Additionally, I recommend avoiding "1:height(cameraPoses)" for codegen here. If "cameraPoses" is the codegen struct, "height(cameraPoses)" is not the number of poses. Use "numel(cameraPoses.ViewId)" and preserve the actual ViewId values so they still match "tracks.ViewIds".
“One-dimensional indexing” means codegen is seeing an object array that only supports linear indexing like "pose(k)", but something in the generated validation path is trying table/row-style indexing. Making "AbsolutePose" a cell column avoids that path failing.
Hope this resolves the issue.
Regards,
Matt.

1 Comment

That solved the issue! Thank you so much.

Sign in to comment.

More Answers (0)

Categories

Find more on Code Generation in Help Center and File Exchange

Products

Release

R2026a

Asked:

on 10 Jul 2026

Commented:

on 18 Jul 2026

Community Treasure Hunt

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

Start Hunting!