I have a cumulative vector, size is about 200. I want to pick up that index where value is 0,5 or value which is next to it. For example (0.1, 0.23, 0.42, 0.49, 0.52, 0.56,...), so i want to pick up index which corresponding to value 0.52. How can I do it?
No products are associated with this question.
Here is one approach:
v = [0.1 0.23 0.4 0.52 0.56 1.1] idx = find(v >= 0.5,1,'first') v(idx)
To do this for multiple values, take a look at my function NEARESTPOINT:
v = [0.1 0.23 0.4 0.52 0.56 1.1]; [absdist, nearest] = min(abs(v - 0.5)); % **SOLUTION IS HERE** !!! if absdist == 0 % or: <= eps(v(index)) following = index; else following = index + 1; end
nearestValue = value(nearest); followingValue = value(following);
Play games and win prizes!Learn more