フィルターのクリア

How to find the lowest distance?

1 回表示 (過去 30 日間)
vinicius lanziotti
vinicius lanziotti 2017 年 12 月 8 日
コメント済み: vinicius lanziotti 2017 年 12 月 8 日
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 = ?

採用された回答

Guillaume
Guillaume 2017 年 12 月 8 日
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 件のコメント
vinicius lanziotti
vinicius lanziotti 2017 年 12 月 8 日
Very nice. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by