Matlab running out of memory on code

AI Thread Summary
MATLAB is running out of memory when executing code designed to find combinations of integers that meet specific conditions. The code involves generating combinations of integers and checking them against a set of criteria, which leads to excessive memory usage, especially for larger values of NumberOfVariables. The user is seeking to identify the first valid combinations that do not include zeros for various specified values of NumberOfVariables. Suggestions include using print statements to monitor array sizes during execution to better manage memory consumption. Optimizing the code to improve computational efficiency is crucial to prevent MATLAB from crashing.
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.
 
Back
Top