All possible combinations of a matrix

1 view (last 30 days)
Andrew Higgins
Andrew Higgins on 13 Feb 2024
Edited: John D'Errico on 13 Feb 2024
I have a 10x20 int32 matrix which represent Y values across tests (20 tests at 10 points each.) I want to find each possible combination of Y, which if my math is right is 1.024^13 unique combinations. Is there a way to find a Y combination, do some math with it, clear it, then move on to the next Y combination and so on for all combinations without nested for loops? Thanks!

Answers (1)

John D'Errico
John D'Errico on 13 Feb 2024
Edited: John D'Errico on 13 Feb 2024
Did you intend to write 1.024^13? This is not even an integer, and only a little larger than 1.
1.024^13
ans = 1.3611
So there are 1.3611 unique combinations? I doubt it. I assume you meant to write 1.024e13. But...
Even if your math is correct, then there are still roughly 1e13 combinations. It is not at all clear what you mean by combinations here, or where the 1.024e13 came from. But suppose we assume that to be correct.
Assume that you can do this iterative scheme as you want to do. (There are things you can do as I recall.) But even assuming that, suppose you can process 1 million such combinations per second. So 1e6 per second. Considering the overhead of computing the next combination from the previous one, and whatever you will do for each combination, that seems reasonable, at least possible. There are roughly 31.5 million seconds in a year. So this little scheme of yours might be done in
1.024e13/1e6/31.5e6
ans = 0.3251
A third of a year, or roughly 4 months of CPU time to do the work. FLAT OUT. 24 hours per day.
Sadly, too often we think our computers are all powerful. And we forget to think about just how large some numbers are. 1e13 is not even that huge really. But it is large enough that your next question will be in how to improve the speed of your code.
The answer is usually to NOT use brute force to do these computations, but to use optimization techniques in some way, or to use mathematics to solve the problem in some tractable way. We are not told what it is you are doing, so giving you better help is going to be difficult.

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!