필터 지우기
필터 지우기

Sort and rearranged a 1D array to 3D matrix

조회 수: 4 (최근 30일)
K3iTH
K3iTH 2023년 3월 29일
댓글: K3iTH 2023년 3월 30일
Hello all,
I have matrix with the size of 60x150x150. I have reshaped it into a 1D array and sorted it so the value is in descending order.
What I want to do next is rearrange this 1D array back to the the 3D matrix with the size of 60x150x150. The cell is filled in the X direction (150) with Z=1 and starting from 151, it will begin from z=2. After it filling up 22500 cells (XxZ = 150x150), then only it will start from Y=2.
The code below creates TEMP matrix and sorted the 1D named sortedTEMP. May I know how can I do that? I am not sure how to start with putting the cell back into 3D. I have tried reshape function and it is not working.
Thanks for your help!!
xx = linspace(-15,15,150);
zz = linspace(-15,15,150);
yy = linspace(0,1,60);
[X,Y,Z] = meshgrid(xx,yy,zz);
R = sqrt(X.^2 + Z.^2);
TEMP = 1.0+(1.0-tanh((R-1.0)/0.01))*0.5/10.0;
TEMP_norm = (TEMP -1)/0.1;
xslice = []; % location of y-z planes
yslice = 0.5; % location of x-z plane
zslice = []; % location of x-y planes
slice(X,Y,Z,TEMP_new,xslice,yslice,zslice);
xlabel('x')
ylabel('y')
zlabel('z')
oneDTEMP = reshape(TEMP,[],1); % reshape into 1D array
sortedTEMP = sort(oneDTEMP,'descend'); % rearrange value from high to low
TEMP_new = zeros(size(TEMP));
  댓글 수: 1
K3iTH
K3iTH 2023년 3월 30일
Hello all,
I have managed to solve this by myself.
Thanks for your help!

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

답변 (1개)

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 3월 29일
Hello,
You could add these lines to the end of your code
[sx,sy,sz]=size(TEMP);
A=reshape(sortedTEMP,[sx*sz,sy])';
for i=1:sx
Z(i,:,:)=A(:,(i-1)*sz+1:(i-1)*sz+sz);
end

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by