Effacer les filtres
Effacer les filtres

generate 11x11x11 symmetric matrix from 6x6x6 matrix

1 vue (au cours des 30 derniers jours)
Jim O'Doherty
Jim O'Doherty le 7 Nov 2012
Hello,
I'm slowly going mad trying to accomplish something I feel is actually rather simple.
I've got a 6x6x6 matrix which I would like to be symmetric around all the principal axes about the point (1,1,1), thus making me an 11x11x11 matrix. Rather than having to do this the long way (and I have quite a few arrays to do this on), is there a quick command that would do this for me, perhaps some combination of fliplr/flipud?
Thanks,
Jim
  4 commentaires
Jim O'Doherty
Jim O'Doherty le 7 Nov 2012
Modifié(e) : Jim O'Doherty le 7 Nov 2012
Apologies, yes I meant an array rather than matrix.
The "long way" would be me manually copying the array values into their correct positions.
Maybe its best shown with a 2-D example (I've shortened the array from 6x6 for space):
t=[788404.4 122836.9 2857.7
122836.9 32833.4 994.4
2857.7 994.4 31.9
7.3 5.4 3.9
3.2 3.0 2.6
2.1 2.0 1.8
];
should result in:
t_r = [2857.7 122836.9 788404.4 122836.9 2857.7
994.4 32833.4 122836.9 32833.4 994.4
31.9 994.4 2857.7 994.4 31.9
3.9 5.4 7.3 5.4 3.9
2.6 3.0 3.2 3.0 2.6
1.8 2.0 2.1 2.0 1.8
];
For a 2D matrix, this "flip" in matrix "t" would happen to the left and upwards, so that the value 788404.4 located at (1,1) would become the value at the centre of the new matrix
EDIT: the new matrix would now be of dimensions 11x5
Jan
Jan le 7 Nov 2012
And Jose-Luis' question would result in:
a = [1 2;
3 4];
b = [4 3 4;
2 1 2;
4 3 4];
You example handles the columns only. But "[6x6x6]->[11x11x11]" implies, that the rows should be handled also. Am I right?

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 7 Nov 2012
Modifié(e) : Jan le 7 Nov 2012
n = 6;
A = rand(n, n, n);
v = [n:-1:2, 1:n];
B = A(v, :, :);
C = B(:, v, :);
D = C(:, :, v);
  2 commentaires
Jim O'Doherty
Jim O'Doherty le 7 Nov 2012
Thank you so much, this is exactly what I was looking to achieve!
Jim
Jan
Jan le 7 Nov 2012
There must be a one-liner also. Unfortunately I cannot run Matlab currently to test this.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by