9

Let's say I have a 100x100 matrix, I want to divide it into equal parts of 10x10.

The problem is that the input matrix can be of any size (but always mod 10). I looked at the mat2cell function but it does not seem to work for a dynamic number of parts. Or am I missing something?

Shai
  • 111,146
  • 38
  • 238
  • 371
Hubert Perron
  • 3,022
  • 5
  • 34
  • 28
  • 5
    If your goal is to ultimately process these sub-matrices, perhaps you want to consider using the block processing functions in the Image Processing Toolbox (ex: **blockproc**), refer to: http://www.mathworks.com/access/helpdesk/help/toolbox/images/f7-12726.html – Amro Nov 30 '09 at 00:18

1 Answers1

13

You just have to tell mat2cell exactly how you want the matrix divided up. If you're positive that it is always going to be a multiple of 10 in both directions, then it is (fairly) simple. Assuming that X is the matrix that you want to divide, and you want the resulting cell array in Y:

Y = mat2cell(X, repmat(10,[1 size(X,1)/10]), repmat(10,[1 size(X,2)/10]));

Donnie
  • 45,732
  • 10
  • 64
  • 86