Matlab running out of memory on code

Click For Summary
SUMMARY

The discussion focuses on a MATLAB code that runs out of memory when attempting to generate combinations for a specified number of variables, specifically 9, 10, 12, 14, 17, and 20. The user employs the combnk function to create combinations but faces performance issues due to the exponential growth of data. The solution involves optimizing the code to prevent memory overflow while still achieving the desired output of combinations that meet specific conditions.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with combinatorial functions, specifically combnk
  • Knowledge of memory management in MATLAB
  • Basic concepts of algorithm optimization
NEXT STEPS
  • Research MATLAB memory management techniques to handle large datasets
  • Learn about vectorization in MATLAB to improve code efficiency
  • Explore alternative combinatorial algorithms that reduce memory usage
  • Investigate the use of parfor loops for parallel processing in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB programmers, data scientists, and researchers working with large datasets who need to optimize their code for performance and memory usage.

IKnowNada
Messages
2
Reaction score
0

Homework Statement


I am trying to run code for the code below but MATLAB runs out of data.

The Attempt at a Solution


NumberOfVariables = 9;
k=NumberOfVariables^2-NumberOfVariables+1;
integers = 0:k-1;
numbers = 1:k-1;
tic
s = combnk(integers,NumberOfVariables);
AllAnswers = [];
for i = 1:size(s,1)
G=combnk(s(i,:),2);
G = [(G(:,1)'-G(:,2)') (G(:,2)'-G(:,1)')];
G = sort(mod(G,k));
if (isequal(G,numbers))
AllAnswers = [AllAnswers;s(i,:)];
end
end
toc

I am trying to find the numbers that satisfy the condition in the code. I want the first AllAnswers that do not contain zeros for NumberOfVariables = 9,10,12,14,17,20?I wrote code for the for loops, but as we all know that doesn't scale favorably in computational time and MATLAB crashes.
 
Physics news on Phys.org
I would try placing print statements inside the code to see how large each array is as you keep adding stuff to the all answers array.
 

Similar threads

Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
1
Views
2K