MATLAB: The program is not running, and how to run it

for loopmatrix indexing

x = zeros(1,9);
relation = zeros(9,9);
relation =[0 0 0 0 5 5 5 0 0;
0 0 5 0 0 0 0 5 0;
0 5 0 0 0 0 0 0 5;
0 0 0 0 0 0 0 5 0;
5 0 0 0 0 0 0 0 5;
5 0 0 0 0 0 0 0 0;
5 0 0 0 0 0 0 0 0;
0 0 0 5 0 0 0 0 0;
0 0 5 0 5 0 0 0 0;];
check =0;
for x(1)=0:1
for x(2)=0:1
for x(3)=0:1
for x(4)=0:1
for x(5)=0:1
for x(6)=0:1
for x(7)=0:1
for x(8)=0:1
for x(9)=0:1
sum=0;
for n=1:9
sum = sum + x(n);
end
if sum == 5
value=0;
for count1 = 1:9
for count2 =count1:9
value = x(count1)*x(count2)*relation(count1,count2);
end
end
end
if value>check
reply_value = value;
reply_x =x;
end
end
end
end
end
end
end
end
end
end

Best Answer

You cannot use an indexed variable for a "for" loop variable.
By the way:
X = dec2bin(0:2^9-1) - '0';
mask = sum(X, 2) == 5;
X5 = X(mask, :);
Now X5 is a (something) by 9 array in which every row has sum 5. You can work on your processing from there.