Effacer les filtres
Effacer les filtres

How to find the lowest distance?

1 vue (au cours des 30 derniers jours)
vinicius lanziotti
vinicius lanziotti le 8 Déc 2017
x = [1 2 3 4 5];
d = [0 10 20 30 40
10 0 50 60 70
20 50 0 80 90
30 60 80 0 100
40 70 90 100 0];
for k=1:n
xp = randperm(numel(x), 2);
x(xp) = x(fliplr(xp))
s = sub2ind(size(d),x(1:end-1),x(2:end ));
Distance = sum(d(s))
end
Lowest_Distance = ?

Réponse acceptée

Guillaume
Guillaume le 8 Déc 2017
Using words to explain what you want would be useful, rather than leaving it up to the reader to guess.
Also using comments in your code would be useful to explain what it is doing (the big picture).
A guess, that you want the minimum of the Distance values calculated at each step of your k loop. In that case, simply store the values into an array and take the minimum:
Distance = zeros(1, n);
for k = 1:n
...
Distance(k) = sum(d(s));
end
min_Distance = min(Distance)
  1 commentaire
vinicius lanziotti
vinicius lanziotti le 8 Déc 2017
Very nice. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by