HOW TO RESHAPE 3D ARRAY WITH DIFFERENT DIRECTIONS?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
DGM
on 21 Aug 2021
Edited: DGM
on 21 Aug 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!