Combine matrix (three-in-one)
Afficher commentaires plus anciens
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 commentaire
Image Analyst
le 5 Déc 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.
Réponses (3)
Star Strider
le 5 Déc 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]
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 commentaire
Timofey
le 5 Déc 2014
Image Analyst
le 5 Déc 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,:)']
Catégories
En savoir plus sur Simulink dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!