フィルターのクリア

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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by