Nearest MATLAB

I want to find the index of the nearest element in x=0:0.1:pi/2 to a given number z=0.65 . I already did this, but I need something better: [C,I]=min(abs(xz)) . I is the index of the nearest element.

+4
source share
1 answer

[C, I] = min(abs(xz)) - this is what I will do - I can not come up with improvements on this. [~, I] = min(abs(xz)) will allow you not to create an unnecessary C variable if you consider this an improvement.

+6
source

Source: https://habr.com/ru/post/1383228/


All Articles