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,
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