solving memory problem for this code

3 views (last 30 days)
NA
NA on 19 May 2019
Answered: Walter Roberson on 19 May 2019
I run this code for X that has size 42*12
if size(X,2)==1
M=0;
end
n = size(X, 1);
rank_X = rank(X);
for d = 1:(n-1)
newn = n - d;
indices_matrix = combnk(1:n, newn);
Mset = 0; % for breaking the loop need to define initial value
for j = 1:size(indices_matrix, 1)
indices = indices_matrix(j, :);
X_minus_d = X(indices, :);
rank_X_minus_d = rank(X_minus_d);
if (rank_X_minus_d < rank_X)
dstar = d;
M = n - dstar;
Mset = 1;
break
end
end
if Mset == 1 % breaking from first loop
break
end
end
And gives this error
Out of memory.
How can I fix this problem?

Answers (1)

Walter Roberson
Walter Roberson on 19 May 2019
You cannot fix that. combnk(1:n,newn) takes all combinations of 1:n, newn at a time, where your n is 42, and newn is 41 down to 1. The maximum number of combinations is 538257874440 when newn = 21 . For that, each entry would be length 21 doubles, 8 bytes per double, so you would need 538257874440 * 21 * 8 = 90427322905920 bytes, which is about 83 terabytes of memory. Do you have that much RAM in your system?:

Categories

Find more on Image Processing Toolbox 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!