필터 지우기
필터 지우기

Help needed with the find function

조회 수: 1 (최근 30일)
Aftab Ahmed Khan
Aftab Ahmed Khan 2016년 7월 14일
댓글: Aftab Ahmed Khan 2016년 7월 14일
Hello everyone, I have this section of code. I want to find the closest node among the two sets of base stations. The way i am doing it is like this but the find function gives me an error.
closest_dist=min(distance_ua(iduser,:),distance_ur(iduser,:));
closest_node=(find(distance_ua(iduser,:)==closest_dist)) || (find(distance_ur(iduser,:)==closest_dist));
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2016년 7월 14일
Aftab - wouldn't the closes to the ABS or RBS be the minimum of closest_abs and closest_rbs or am I misunderstanding something?
Aftab Ahmed Khan
Aftab Ahmed Khan 2016년 7월 14일
Hi Geoff, I just amended the question to explain it more properly.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2016년 7월 14일
편집: Guillaume 2016년 7월 14일
Note that using
indices = find(x == min(x))
only makes sense if you have several values equal to the minimum and you want to get the indices of all these values. Otherwise,
[~, index] = min(x)
is a more efficient way of getting the index of the first minimum.
Assuming, that the number of columns in distance_ua and distance_ur is the same and that the indices in distance_ua and distance_ub mean the same, then:
d_ua_ur = [distance_ua(iduser, :), distance_ur(iduser, :)];
closest_abs_or_rbs = mod(find(d_ua_ur == min(d_ua_ur)) - 1, size(distance_ua, 2)) + 1
edit: missing closing bracket
  댓글 수: 4
Aftab Ahmed Khan
Aftab Ahmed Khan 2016년 7월 14일
I noticed that earlier but still it gives the same error.
Aftab Ahmed Khan
Aftab Ahmed Khan 2016년 7월 14일
Done, thanx.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by