I have a 4D array
MM = [ 2.*N+1 , 2.*N+1 , Cylinder , Cylinder ] ;
where N is a scale for a contour plot and Cylinder defines the number of 2N+1 x 2N+1 arrays; so for example, N = 100 and Cylinder = 3 would produce an array of nine 201 x 201 square matrices. I want to reshape MM into a square 2D matrix, so the output always has a consistent format as the values of N and Cylinder vary.
For example, Cylinder = 2 would give MM the structure
val(:,:,1,1) = ...val(:,:,2,1) = ...val(:,:,1,2) = ...val(:,:,2,2) = ...
I want to reshape it as
[ val(:,:,1,1) , val(:,:,2,1) ; ... val(:,:,1,2) , val(:,:,2,2) ] ;
So for Cylinder = 3, I want
[ val(:,:,1,1) , val(:,:,2,1) , val(:,:,3,1) ; ... val(:,:,1,2) , val(:,:,2,2) , val(:,:,3,2) ; ... val(:,:,1,3) , val(:,:,2,3) , val(:,:,3,3) ] ;
and Cylinder = 4,
[ val(:,:,1,1) , val(:,:,2,1) , val(:,:,3,1) , val(:,:,4,1) ; ... val(:,:,1,2) , val(:,:,2,2) , val(:,:,3,2) , val(:,:,4,2) ; ... val(:,:,1,3) , val(:,:,2,3) , val(:,:,3,3) , val(:,:,4,3) ; ... val(:,:,1,4) , val(:,:,2,4) , val(:,:,3,4) , val(:,:,4,4) ] ;
etc. How can this structure be achieved for any value of N and Cylinder?
Best Answer