How do I convert a group of 3x3 matrices that are contained in a 3xN array, into a 3x3xN/3 array?

조회 수: 10 (최근 30일)
I'm a bit at a loss. I have an array of 2 different 3x3 rotation matrices represented in a 3x6 array, I'd like to conver that to a 3x3x2 array, but it converts in a way that doesn't match the original order of the 3x3 arrays.
I'm looking to start here
A =
[0.9053 -0.4246 -0.0002;
0.4246 0.9053 0.0001;
0.0002 -0.0002 0.9999;
0.9053 -0.4245 0.0001;
0.4245 0.9053 0.0000;
-0.0001 0.0000 0.9999];
and end here
B =
val(:,:,1) =
0.9053 -0.4246 -0.0002;
0.4246 0.9053 0.0001;
0.0002 -0.0002 0.9999
val(:,:,2) =
0.9053 -0.4245 0.0001;
0.4245 0.9053 0.0000;
-0.0001 0.0000 0.9999
I can't represent it in the tags, but I have all official matlab toolboxes

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 10월 18일
MATLAB uses column-major order by default, which means the data is organized internally as if the columns were stacked head-to-tail on tope of each other (what you see when you do A(:)). When you reorgainze the data to be 3x3xN, it fills the columns of the new array column by column, using all the data in the first column of A, then the second, etc.
Since your columns stay fixed, you can take advantage of the transpose operator along with the reshape and permute functions.
A = [0.9053 -0.4246 -0.0002;
0.4246 0.9053 0.0001;
0.0002 -0.0002 0.9999;
0.9053 -0.4245 0.0001;
0.4245 0.9053 0.0000;
-0.0001 0.0000 0.9999];
% Reshape and permute
val = reshape(A',3,3,[]);
val = permute(val,[2,1,3])
val =
val(:,:,1) = 0.9053 -0.4246 -0.0002 0.4246 0.9053 0.0001 0.0002 -0.0002 0.9999 val(:,:,2) = 0.9053 -0.4245 0.0001 0.4245 0.9053 0 -0.0001 0 0.9999

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by