How to get part of 2D array from a 2D array. (i.e. 4x4 array to 2x2x4)

2 vues (au cours des 30 derniers jours)
K.S.
K.S. le 27 Nov 2020
Commenté : K.S. le 30 Nov 2020
I would like to disassemble 2D array to specific size of 2D array as following image without "for loop".
I know, we can use for loop to get that.
test=[1 1 2 2; 1 1 2 2; 3 3 4 4; 3 3 4 4];
k=0;
for j=1:2:size(test,1)
for i=1:2:size(test,2)
k=k+1
DisassembleArray(:,:,k)=test(j:j+1,i:i+1)
end
end
Is it possible to disassemble 2D array as I mention?
If yes, could you show me a sample code?

Réponse acceptée

David Hill
David Hill le 27 Nov 2020
A=reshape([a(1:2,:),a(3:4,:)],2,2,4);
  1 commentaire
K.S.
K.S. le 30 Nov 2020
Thank you very much answer for me.
I will try to use reshape function.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by