Converting the 3D Matrix to 2D Matrix

1 vue (au cours des 30 derniers jours)
Marimuthu Ananthavelu
Marimuthu Ananthavelu le 16 Avr 2018
I have a matrix outputs from my function in the following form;
zeros(3,5,5)
Basically, its a result of pairwise comparison of a matrix
(5 x 5)
for
3
different modalities (types).
I wish to convert this matrix with each pairwise comparison matrix separately with respect to different modalities.i.e I wish to have the result as below;
1 2 3
i1 j1 k1
i2 j2 k2
i3 . .
i4 . .
i5 . .
i6 . .
. . .
. . .
. . .
. . .
i25 j25 k25
I checked the example using Reshape and could not get much from it. Can anyone please help me through? Thanks
  2 commentaires
Birdman
Birdman le 16 Avr 2018
What have you tried?
Jan
Jan le 16 Avr 2018
I do not understand, what "i1, j1, k1" means. Where are they found in the original data? The problem can be solved by:
y = reshape(permute(reshape(x, Size1), Order2), Size3)
All you need is to find the matching parameters Size1, Order2 and Size3.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 16 Avr 2018
Modifié(e) : Jan le 16 Avr 2018

The general reordering of elements can be done by:

y = reshape(permute(reshape(x, Size1), Order2), Size3)

In your case (perhaps - still not sure what "i1, j1, k1 etc" means):

x = zeros(3,5,5);
x(:) = 1:3*5*5;   % Some test data
y = reshape(permute(reshape(x, 3, 25), [2, 1]), [25, 3])

If this is the wanted output, there is an abbreviation:

y = reshape(x, 3, 25).'

permute(Matrix, [2,1]) is the same as mtranspose() and the 2nd reshape is not required here. But it is worth to keep the general transformation in mind.

  1 commentaire
Marimuthu Ananthavelu
Marimuthu Ananthavelu le 18 Avr 2018
Hi please note that the i,j,k are nothing but the elements of the matrix. And I just mentioned them for the sake of clarity. Thanks for your answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by