rotate acceleration vector using rotation matrix

6 ビュー (過去 30 日間)
Adam Levschuk
Adam Levschuk 2020 年 3 月 17 日
コメント済み: James Tursa 2020 年 3 月 17 日
Hello, first time question asker here.
I am trying to orient a smartphone whlist it is in a persons pocket. I collected accelerometer, gyroscope, and magnetometer data from the phone. Next i used the ahrsfilter to output quaternions relative to the NED reference frame.
Next i created a rotation matrix using rotationMatrix = quat2rotm(orientation). this gave me my rotation matrix.
Now here is the problem. My acceleration data which i want to rotate is in a 940x3 (X Y Z) array and my rotation matrix is in a 3x3x940 multidimensional array. So, how can i multiply each of my acceleration points with the appropriate rotation matrix. I suspect i will have to use a loop, however i am unsure about how to do this. How would you go about doing this?
Thank you

採用された回答

James Tursa
James Tursa 2020 年 3 月 17 日
編集済み: James Tursa 2020 年 3 月 17 日
You can use a loop, e.g.
acc = your 940x3 matrix
r = your 3x3x940 array
result = zeros(size(acc));
for k=1:size(acc,1)
result(k,:) = r(:,:,k) * acc(k,:)';
end
Depending on how r is defined (you didn't specify) you might need this instead:
result(k,:) = acc(k,:) * r(:,:,k);
Or you can explore using one of these FEX submissions (some of which require a C/C++ compiler to create mex routines):
  2 件のコメント
Adam Levschuk
Adam Levschuk 2020 年 3 月 17 日
worked perfectly! thank you for the quick repsonse and great answer. =
I learned a bit more about loops just by using that.
Question: why did create an array of zeros the size of the acceleration matrix?
Thanks again.
James Tursa
James Tursa 2020 年 3 月 17 日
The zeros( ) stuff is siimply pre-allocating the memory for the result before getting into the loop.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecialized Messages についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by