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
MATLAB: The program is not running, and how to run it
for loopmatrix indexing
Best Answer