Asked by sharifah shuthairah syed abdullah
on 13 Oct 2018

i have this coding, i want to have make a loop of for 10 iteration.. the curent coding didnt give me 10 iteration..

i want to have 10 possible solution however its only show 1 solution. below is the coding. what can i do to make it generate 10 solution

%read data

clc

clear

%global f d;

%flow

f=[ 0 5 2 4 1

5 0 3 0 2

2 3 0 0 0

4 0 0 0 5

1 2 0 5 0];

%distance

d=[ 0 1 2 3 1

1 0 1 2 2

2 1 0 1 3

3 2 1 0 4

1 2 3 4 0];

[r,c]=size(f);

max_i= r;

max_j =r;

max_k= r;

max_q= r;

A=zeros(r,r);

ID=randperm(r);

MaxIt=10;

x=zeros(r,r);

n=length(ID);

x1=ID;

for i=1:n

for j=1:r

x(j,x1(j))=1;

B(i).mat=x; %store permutationof binary value, 0,1

end

x=zeros(r,r);

end

for i=MaxIt

for no=1:length(B)

z=0;

xa=B(no).mat;

for i=1:max_i

for j=1:max_j

for k=1:max_k

for q=1:max_q

z= z+ f(i,k).*d(j,q).*xa(i,j).*xa(k,q);

end

end

end

end

end

no;

F(no,:)=[no z];

end

zmin=min(F(:,2));

ii=find(F(:,2)==zmin) ;

x_initial = B(ii).mat;

xbin= B(ii).mat

z_minimum = zmin

%disp(B(ii).mat)

%fprintf (B(no).mat);

%disp(z)

Opportunities for recent engineering grads.

Apply Today
## 10 Comments

## madhan ravi (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_621957

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_622134

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623569

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623570

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623573

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623579

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623614

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623641

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623857

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_624081

Sign in to comment.