Ask for help on optimizing a permutation problem

Hi everyone,

I have one optimization problem with pressed deadline. It looks simple to understand but puzzle me for a while.

Here is the description:

We have a 5*10 Matrix. Each column out of 10 have several non-zero elements and are arranged on the top closely. The rest of the column will be all zeros.

Now we pick up one non-zero element from each column and put the 10 elements together to get a new vector.

Then it comes to the problem that how to find out all possible vectors? The original source code use a 10-level for loops to get all possible vectors, but it is really slow. And my task is find another algorithm or Matlab function to replace the 10 level for loops.

If you could help, please! Only an idea is also more than welcomed! Thank you in advance!

Here is an example matrix and vector:

1 2 4 5 3 1 2 1 7 2

3 3 8 6 5 3 3 2 9 5

7 5 9 7 0 4 5 4 0 6

0 6 0 8 0 5 7 5 0 7

0 0 0 9 0 0 0 8 0 0

a possible vector:

(1 3 4 6 3 5 2 1 9 2 )