I'm sure it is possible. Mathematica is a full-blown programming language with loops, if's, increments, etc. One command that will be helpful is the Dimensions command. For example,

Dimensions[{{1, 2}, {3, 4}, {5, 6}}] returns

{3,2}.

You can access the first component of the result by indexing, which in Mathematica looks like this: [[i]]. So, for example,

Dimensions[{{1, 2}, {3, 4}, {5, 6}}][[1]] returns

3

and

Dimensions[{{1, 2}, {3, 4}, {5, 6}}][[2]] returns

2.

One more comment: indexing into a matrix looks like this:

A[[1]][[4]], which gives you the 1,4 element of the matrix. For example,

{{1, 2}, {3, 4}, {5, 6}}[[3]][[1]] returns

5.

I would set up some sort of a nested looping program to do what you are asking. Does this help?