MATLAB: Automatic creation of variables and expansion of matrices in m-files

Hello everyone. I am new to these forums, so apologies if I've inadvertantly posted this in the wrong section of the forum..

I needed some help with a MATLAB m-file I am constructing.

Currently, I have a series of while loops, within while loops generating a large number of calculations. The number of calculations done is about 2.4mil, but the number of answers generated are only a few thousand (as many of the calculations result in a common answer).

Everytime a NEW answer is generated, I am using the eval function to generate a variable with the name of the answer.

What I need to do, but am not sure how to, is somehow link all the scenarios to their respective answer.

For example, if Answer No. (and hence variable number) is 5,000, then I need to somehow create a matrix from this variable which lists all the loops out of the 2.4million that resulted in this answer.

Hopefully I've explained this clearly enough.

I thank you in advance for taking the time to read my dilemma.