Combine matrix (three-in-one)

조회 수: 11 (최근 30일)
Timofey
Timofey 2014년 12월 5일
댓글: Image Analyst 2014년 12월 5일
I have three matrix : x,y,z
X =
  • X11 X12 X13
  • X21 X22 X23
  • X31 X32 X33
Y=
  • Y11 Y12 Y13
  • Y21 Y22 Y23
  • Y31 Y32 Y33
Z=
  • Z11 Z12 Z13
  • Z21 Z22 Z23
  • Z31 Z32 Z33
How i can combine this matrix, for this result:
P=
  • X11 Y11 Z11
  • X12 Y12 Z12
  • X13 Y13 Z13 and etc..
Please help me
  댓글 수: 1
Image Analyst
Image Analyst 2014년 12월 5일
Explain what "and etc." means. Aren't you just making the columns of P the first row of X, Y, and Z? So what "etc." could there be? Please clarify/expand in case we need to modify our answers.

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

답변 (3개)

Star Strider
Star Strider 2014년 12월 5일
This is done symbolically for illustration, but the permute function is likely what you want:
X = sym('X%d%d',[3 3]);
Y = sym('Y%d%d',[3 3]);
Z = sym('Z%d%d',[3 3]);
P(:,:,1) = X;
P(:,:,2) = Y;
P(:,:,3) = Z;
P1 = permute(P, [2 3 1])
produces:
P1(:,:,1) =
[ X11, Y11, Z11]
[ X12, Y12, Z12]
[ X13, Y13, Z13]
P1(:,:,2) =
[ X21, Y21, Z21]
[ X22, Y22, Z22]
[ X23, Y23, Z23]
P1(:,:,3) =
[ X31, Y31, Z31]
[ X32, Y32, Z32]
[ X33, Y33, Z33]

B. C.
B. C. 2014년 12월 5일
편집: B. C. 2014년 12월 5일
If you want P to have 9 lines and 3 columns, you can do
X2=X'; Y2=Y'; Z2=Z';
P = [X2(:) Y2(:) Z2(:)];
clear X2 Y2 Z2
Note that it might exist something faster.
  댓글 수: 1
Timofey
Timofey 2014년 12월 5일
Is it possible to create a loop ?

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


Image Analyst
Image Analyst 2014년 12월 5일
To put the first rows of the 3 matrices as the columns of a new matrix P, do this:
P = [X(1,:)', Y(1,:)', Z(1,:)']

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by