Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

hello i have some doubts about using recursive method about making matrix into sub matrices and should be saved in a single array.

Asked by pavan kumar uppala on 26 Jun 2013

I want to take input a 4 by 4 matrix and then make that into a single 1 by 1 sub matrices using reshape command in "recursive method". Recursive method is the main criteria. the should be saved in the form of single array. i also have a condition that i should not use mat2cell or for loop. while loop is accepted.

the code which i have am submitting it below

clear all
clc
A=[1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16]
%A=magic(16)
% b=reshape(A',[1,16]),
r1=reshape(A,[4,2,2]),
r11=transpose(r1(:,:,1)),
r22=transpose(r1(:,:,2)),
d1=reshape(r11,[2,2,2]),
d2=reshape(r22,[2,2,2]),
d11=transpose(d1(:,:,1)),
d12=transpose(d1(:,:,2)),
d21=transpose(d2(:,:,1)),
d22=transpose(d2(:,:,2)),
DD(:,:,1)=d11;
DD(:,:,4)=d12;
DD(:,:,2)=d21;
DD(:,:,3)=d22;
DD

0 Comments

pavan kumar uppala

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov on 27 Jun 2013
A= reshape(1:24,6,[])'; % your array
s = size(A);
m = [2 3];              % size of your block
t = reshape(A,m(1),s(1)/m(1),m(2),s(2)/m(2));
t = permute(t,[1 3 4 2]);
t(:,:,:,2) = flipdim(t(:,:,:,2),3);
out = reshape(t,m(1),m(2),[]);

0 Comments

Andrei Bobrov

Contact us