If each element of the 3D matrix takes one value of 4 discrete values. How can I obtain all possible combinations of this 3D matrix?

3 views (last 30 days)
If each element of 3D matrix of dimensions (10,10,2) takes one value from this vector [0 0.625 1.25 2.5] . How can I obtain all possible combinations of this 3D matrix ?

Accepted Answer

Walter Roberson
Walter Roberson on 7 May 2017
With 4 possible values for each entry, the number of different possibilities would be 4^10 * 4^10 * 4^2, which would be 17592186044416 matrices, which is 2^44 matrices. Each matrix would require 10*10*2 = 200 doubles, and each double would require 8 bytes. The total storage requirements would exceed 2^54 bytes.
Unfortunately for you, no released version of the x64 architecture implements more than 48 address pins. You therefore cannot find any MATLAB system anywhere in the world that is able to access enough memory to construct that table.
This hints that you are working on an optimization problem in which you have been thinking that the best way to proceed is to try every possible combination and select the best. You do not have enough memory or time to do that, no matter how well it works "mathematically". You will need to find a different approach.
For example, you can use https://www.mathworks.com/help/gads/mixed-integer-optimization.html ga with integer constraints. The constraints you would use would be that each entry would be 1 to 4. Then, inside your objective function, instead of directly using the x value, you would use the x value to index into your vector to determine the numeric value to use.
Walter Roberson
Walter Roberson on 8 May 2017
YourFunction = @(V) mean(V); %just an example
vector = [0 0.625 1.25 2.5];
T = (uint32(0):uint32(2^14-1));
nT = length(T);
znT = uint8(zeros(nT, 7));
idx = znT;
for K = 1 : 7
idx(:,K) = uint8(1) + uint8(bitget(T, 2*K-1)) + uint8(2) * uint8(bitget(T, 2*K));
suffix_M = vector(idx);
clear idx
wb = waitbar(0, 'processing');
for T1 = T
waitbar(double(T1)/nT, wb);
idx = znT;
for K = 1 : 7
idx(:,K) = uint8(1) + uint8(bitget(T1, 2*K-1)) + uint8(2) * uint8(bitget(T1, 2*K));
prefix_M = vector(idx);
clear idx
this_M_subset = [prefix_M, suffix_M];
these_results = YourFunction(this_M_subset);

Sign in to comment.

More Answers (0)


Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by