You can try the following:
A= [0 0 2 2 2 2 0 0 1 1 1 0 3 3; 2 2 2 2 0 0 1 1 1 0 0 3 3 0]; result = arrayfun(@(b) (A == b).*cumsum((A == b),2),nonzeros(unique(A)), 'UniformOutput', false);
In this example, the variable result will be 3 submatrices.
result = [2x14 double] [2x14 double] [2x14 double]
To access them, use the following syntax:
result{1} result{2} result{3}
Then you will get:
ans = 0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 ans = 0 0 1 2 3 4 0 0 0 0 0 0 0 0 1 2 3 4 0 0 0 0 0 0 0 0 0 0 ans = 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 1 2 0
~ ~ edit
If, as indicated in the comments, A is a three-dimensional matrix, this code works the same, but the structure of the result is slightly different:
result = [2x14x2 double] [2x14x2 double] [2x14x2 double]
To access these matrices, use, for example,
result{1}(:,:,1) % for the results of comparing A(:,:,1) with value 1 result{1}(:,:,2) % for the results of comparing A(:,:,2) with value 1