HOW TO RESHAPE 3D ARRAY WITH DIFFERENT DIRECTIONS?

1 次查看(过去 30 天)
for i = 1:length(j)
NETPLP(:,:,i)= [BPavg1(1,1,i), SPavg1(1,1,i), NETPLP1(1,1,i); BPavg2(1,1,i), SPavg2(1,1,i), NETPLP2(1,1,i); BPavg3(1,1,i), SPavg3(1,1,i), NETPLP3(1,1,i); BPavg4(1,1,i), SPavg4(1,1,i), NETPLP4(1,1,i); BPavg5(1,1,i), SPavg5(1,1,i), NETPLP5(1,1,i); BPavg6(1,1,i), SPavg6(1,1,i), NETPLP6(1,1,i); BPavg7(1,1,i), SPavg7(1,1,i), NETPLP7(1,1,i); BPavg8(1,1,i), SPavg8(1,1,i), NETPLP8(1,1,i)];
end
PL1 = reshape(permute(NETPLP(1,:,:),[1,3,2]), size(NETPLP(1,:,:),1)*size(NETPLP(1,:,:),3), 3);
PL2 = reshape(permute(NETPLP(2,:,:),[1,3,2]), size(NETPLP(2,:,:),1)*size(NETPLP(2,:,:),3), 3);
PL3 = reshape(permute(NETPLP(3,:,:),[1,3,2]), size(NETPLP(3,:,:),1)*size(NETPLP(3,:,:),3), 3);
PL4 = reshape(permute(NETPLP(4,:,:),[1,3,2]), size(NETPLP(4,:,:),1)*size(NETPLP(4,:,:),3), 3);
PL5 = reshape(permute(NETPLP(5,:,:),[1,3,2]), size(NETPLP(5,:,:),1)*size(NETPLP(5,:,:),3), 3);
PL6 = reshape(permute(NETPLP(6,:,:),[1,3,2]), size(NETPLP(6,:,:),1)*size(NETPLP(6,:,:),3), 3);
PL7 = reshape(permute(NETPLP(7,:,:),[1,3,2]), size(NETPLP(7,:,:),1)*size(NETPLP(7,:,:),3), 3);
PL8 = reshape(permute(NETPLP(8,:,:),[1,3,2]), size(NETPLP(8,:,:),1)*size(NETPLP(8,:,:),3), 3);
PL= [PL1;PL2;PL3;PL4;PL5;PL6;PL7;PL8];
LENGTH(J) = 20. IN WHICH I GOT
I WANT VALUES OF PL WITHOUT ASSIGNING THE VARIABLE PL1, PL2, P3, PL4, PL5, PL6, PL7 AND PL8.
PLEASE HELP ME.
  3 个评论
Triveni
Triveni 2021-8-21
编辑:darova 2021-8-21
I have tried this earlier but
PL=NETPLP(1:8,:,:)
PL(:,:,1) =
22 22.05 11.04
22 21.95 -13.96
20.95 21 11.06
21.05 21 -13.94
22 21.95 -13.96
22 20.95 -263.95
22.05 21 -263.95
20.95 21 11.06
I have to rearrange this array. I have to select 1st row from each array then 2nd row to each array and so on. then i have to merge all into single matrix.

请先登录,再进行评论。

采纳的回答

DGM
DGM 2021-8-21
编辑:DGM 2021-8-21
This is why using numbered variables instead of arrays is a bad idea.
No need for a loop. Depending on the size of the inputs, just address the arrays accordingly (pick one)
% assuming that BPavgN, SPavgN, NETPLPN are all mxnx20
NETPLP = [BPavg1(1,1,:), SPavg1(1,1,:), NETPLP1(1,1,:);
BPavg2(1,1,:), SPavg2(1,1,:), NETPLP2(1,1,:);
BPavg3(1,1,:), SPavg3(1,1,:), NETPLP3(1,1,:);
BPavg4(1,1,:), SPavg4(1,1,:), NETPLP4(1,1,:);
BPavg5(1,1,:), SPavg5(1,1,:), NETPLP5(1,1,:);
BPavg6(1,1,:), SPavg6(1,1,:), NETPLP6(1,1,:);
BPavg7(1,1,:), SPavg7(1,1,:), NETPLP7(1,1,:);
BPavg8(1,1,:), SPavg8(1,1,:), NETPLP8(1,1,:)];
% if they are 1x1x20
NETPLP = [BPavg1, SPavg1, NETPLP1;
BPavg2, SPavg2, NETPLP2;
BPavg3, SPavg3, NETPLP3;
BPavg4, SPavg4, NETPLP4;
BPavg5, SPavg5, NETPLP5;
BPavg6, SPavg6, NETPLP6;
BPavg7, SPavg7, NETPLP7;
BPavg8, SPavg8, NETPLP8];
The rest seems simple enough
% reshape the array
PL = reshape(permute(NETPLP,[3 1 2]),[],3);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by