Calculation not having the desired array size

조회 수: 3 (최근 30일)
Wyatt
Wyatt 2024년 9월 29일
댓글: Wyatt 2024년 9월 29일
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;

채택된 답변

Paul
Paul 2024년 9월 29일
Was
% xn(1:3,:) = qF(:,:,i) .* Acc(i,:)' - g;
should be
xn(1:3,:) = (qF(:,:,i) * Acc(i,:).' - g.').';
  댓글 수: 3
Paul
Paul 2024년 9월 29일
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>
Wyatt
Wyatt 2024년 9월 29일
Fixed, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Phased Array Design and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by