Clear Filters
Clear Filters

generate 11x11x11 symmetric matrix from 6x6x6 matrix

1 view (last 30 days)
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 Comments
Jim O'Doherty
Jim O'Doherty on 7 Nov 2012
Edited: Jim O'Doherty on 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 on 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?

Sign in to comment.

Accepted Answer

Jan
Jan on 7 Nov 2012
Edited: Jan on 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 Comments
Jim O'Doherty
Jim O'Doherty on 7 Nov 2012
Thank you so much, this is exactly what I was looking to achieve!
Jim
Jan
Jan on 7 Nov 2012
There must be a one-liner also. Unfortunately I cannot run Matlab currently to test this.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!