MATLAB Answers

0

Help needed with the find function

Asked by Aftab Ahmed Khan on 14 Jul 2016
Latest activity Commented on by Aftab Ahmed Khan on 14 Jul 2016
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 Comments

Aftab - wouldn't the closes to the ABS or RBS be the minimum of closest_abs and closest_rbs or am I misunderstanding something?
Hi Geoff, I just amended the question to explain it more properly.

Sign in to comment.

1 Answer

Answer by Guillaume
on 14 Jul 2016
Edited by Guillaume
on 14 Jul 2016
 Accepted Answer

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 Comments

Show 1 older comment
Guillaume
on 14 Jul 2016
Sorry, there was a missing closing bracket. Fixed now
I noticed that earlier but still it gives the same error.
Done, thanx.

Sign in to comment.