x = [1 2 3 4 5];d = [0 10 20 30 4010 0 50 60 7020 50 0 80 9030 60 80 0 10040 70 90 100 0];Dist = zeros(1,n);for k=1:nxp = randperm(numel(x), 2);x(xp) = x(fliplr(xp)) % vector x permuted in two positions
s = sub2ind(size(d),x(1:end-1),x(2:end ));Dist(k) = sum(d(s));Distance = Dist(1,k) % travaled distance by elements of the vector x
endLowest_Distance = min(Dist)
I need to find the vector x corresponding to Lowest_Distance.
For exemple:
>>
Lowest_Distance = 170
x=
1 2 3 5 4
Best Answer