Replicate and rotate in 4D

조회 수: 2 (최근 30일)
Tuan
Tuan 2013년 6월 3일
Hi all,
Let X1, X2, X3, X4 be row vectors of size [1xN1], [1xN2], [1xN3] and [1xN4] respectively. I would like to replicate and rotate these row vectors to obtain 4 corresponding 4D arrays A1, A2, A3 and A4 with size [N1xN2xN3xN4]. X1 corresponds the 1st dimension of A1, X2 corresponds the 2nd dimension of A2, X3 corresponds the 3rd dimension of A3, and X4 corresponds the 4th dimension of A4. For example, I can obtain A1 and A2 as follows
A1=repmat(X1',[1 N2 N3 N4]);
A2=repmat(X2,[N1 1 N3 N4]);
A3 can be obtained with the following "amateur" code
A3Temp=repmat(X3,[N2 1 N1]); % [N2xN3xN1] array
A3TempRot=rot90_3D_2t(A3Temp,2,3,1,1); % Rotate 2 times to obtain [N1xN2xN3] array
A3=repmat(A3TempRot,[1 1 1 N3]);
For A4, I do not know how to do. After that, I would like to rotate these arrays to obtain [N4xN2xN3xN1] arrays. Do you have any idea about this? Thank you in advance for your help.
Tuan

채택된 답변

Walter Roberson
Walter Roberson 2013년 6월 3일
Have a look at
[A1, A2, A3, A4] = ndgrid(X1, X2, X3, X4);
Also see permute()
  댓글 수: 1
Tuan
Tuan 2013년 6월 3일
Thank you all for your prompt reply. I completely forgot ndgrid function. It seems that ndgrid can answer for both "replicate" and "permute". In fact, to transform X1, X2, X3, X4 into [N4xN1xN2xN3] arrays, we can use [A4,A1,A2,A3]=ndgrid(X4,X1,X2,X3).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Array Geometries and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by