How to find the lowest distance?
조회 수: 1 (최근 30일)
이전 댓글 표시
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 = ?
댓글 수: 0
채택된 답변
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!