brucezepplin
brucezepplin

Reputation: 9792

Divide matrix up into smaller matrix

Hi I have a matrix A size ixi, and i want to divide it into smaller matrices such that each sub matrix fits the dimensions of matrix B size jxj. How do I do this?

B = mat2cell(A,size(B));

doesn't seem to do it.

note: the number of sub matrices = sqrt(n) i.e. if A is 100x100 then there will be 10 sub matrices, If A is 81x81 there will be 9 sub matrices.

Thanks

Upvotes: 0

Views: 1799

Answers (2)

Jonas
Jonas

Reputation: 74940

For mat2cell, if you want to split a matrix into two, you have to give the size for each groups of rows/columns. So if you need to divide a 2-by-2 array into four 1-by-1 arrays, it's mat2cell(array,[1 1],[1 1]).

nSub = sqrt(size(A,1));

B = mat2cell(A,nSub*ones(1,nSub),nSub*ones(1,nSub));

Upvotes: 4

Bornpsycho
Bornpsycho

Reputation: 1

Try repmat. That'll reorganise your axb data into smaller matrices of pxqxr as you require.

Upvotes: 0

Related Questions