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

3 views (last 30 days)
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

Answers (1)

Andrei Bobrov
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),[]);

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!