2

I have a matrix [x y] of size [86 86]. I want to divide this matrix into 10 sub matrix. For thr last matrix there will be shortage of coordinates but can be padded with zeros.

[x y] = size(I)
nSub = 10;
B = mat2cell(I, 2*ones(size(I,1)/2,1), 2*ones(size(I,2)/2,1))

I tried using mat2cell function but the output didn't come well. Can any one tell me where am going wrong or can I change this function

ANUSHA DEVI
  • 225
  • 1
  • 4
  • 17

1 Answers1

2

Does this work for you?

I = rand(86,86);
[x y] = size(I)
nSub = 10;

%// padding
xp = x + nSub - mod(x,nSub);
yp = y + nSub - mod(y,nSub);
I(xp,yp) = 0;

%// submatrices
B = mat2cell(I, nSub*ones(xp/nSub,1),nSub*ones(yp/nSub,1))

enter image description here

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113