필터 지우기
필터 지우기

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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by