Calculation not having the desired array size

2 views (last 30 days)
I am trying to calcumate the Acceleration using a rotational matrix, during the loop the left side is a 3x14074 (good), but the right is (3x3) which I don't want. How can I fix this so the right side has a matching size? Thanks
% Acc and AngV are sensor data sets and have sizes of 14074x3
% qF is 3x3x14074
g = [0,0,9.81];
xn = zeros(3, length(Acc));
fuse = imufilter('SampleRate',100,'DecimationFactor',1);
q = fuse(Acc, AngV);
qF = quat2rotm(q);
for i=1:length(AngV)
xn(1:3,:) = qF(:,:,i) .* Acc(i,:)' - g; % This is where the error arises
end
vi = xn .* dt;
ri = .5 * xn .* (dt^2);
I've tried every combination of transforms and reordering that I could think of, everything gives 3x3 or 3x1. Somehow I used to have this work for me, then I woke up and bam, its broken.
Error:
Unable to perform assignment because the size of the left side is 3-by-14074 and the size of the right side is 3-by-3.
Error in RunKalman (line 27)
xn(1:3, :) = qF(:, :, i)' .* Acc(i, :)' - g;

Accepted Answer

Paul
Paul on 29 Sep 2024
Was
% xn(1:3,:) = qF(:,:,i) .* Acc(i,:)' - g;
should be
xn(1:3,:) = (qF(:,:,i) * Acc(i,:).' - g.').';
  3 Comments
Paul
Paul on 29 Sep 2024
Answered too quickly. Assuming you want xn to have 3 rows and the columns corresponding to the time points
Acc = zeros(100,3); AngV = zeros(100,3);
g = [0,0,9.81];
%xn = zeros(3, length(Acc));
xn = zeros(3, size(Acc,1));
fuse = imufilter('SampleRate',100,'DecimationFactor',1);
q = fuse(Acc, AngV);
qF = quat2rotm(q);
for i=1:length(AngV)
% xn(1:3,:) = qF(:,:,i) .* Acc(i,:)' - g; % This is where the error arises
xn(1:3,i) = qF(:,:,i) * Acc(i,:)' - g'; % This is where the error arises
end
size(xn)
ans = 1×2
3 100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!