Reputation: 7
I have this section of code. I want to find the closest node among the two sets of base stations (ABS and RBS). The way i am doing it is like this but the find function gives me an error. Both the distance matrices is of the same size.
closest_dist=min(distance_ua(iduser,:),distance_ur(iduser,:));
closest_node=(find(distance_ua(iduser,:)==closest_dist)) || (find(distance_ur(iduser,:)==closest_dist));
Upvotes: 0
Views: 71
Reputation: 65460
find
returns an array of index values and ||
only works for values which can be converted to logical scalars. An array of integers cannot be convert to a logical scalar.
[1 2 3] || [1 2 3]
Operands to the || and && operators must be convertible to logical scalar values.
If you want to use the logical OR, you're better off using find
after the operation which would be performed directly on the logical arrays. Additionally, you'll want to use |
instead of ||
to compare two logical arrays.
closest_node = find(distance_uid(iduser, :) == closest_dist | ...
distance_ur(iduser, :) == closest_dist);
Upvotes: 2