Combine matrix (three-in-one)

11 Ansichten (letzte 30 Tage)
Timofey
Timofey am 5 Dez. 2014
Kommentiert: Image Analyst am 5 Dez. 2014
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 Kommentar
Image Analyst
Image Analyst am 5 Dez. 2014
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.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Star Strider
Star Strider am 5 Dez. 2014
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. am 5 Dez. 2014
Bearbeitet: B. C. am 5 Dez. 2014
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 Kommentar
Timofey
Timofey am 5 Dez. 2014
Is it possible to create a loop ?

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 5 Dez. 2014
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,:)']

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by