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.
x=0:0.1:pi/2
z=0.65
[C,I]=min(abs(xz))
I
[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.
[C, I] = min(abs(xz))
[~, I] = min(abs(xz))
C
Source: https://habr.com/ru/post/1383228/More articles:Using matplotlib to mark points on a scatter plot on a mouse using some label other than the x, y coordinates - pythonSuggest # tags when typing (like Twitter) for iPhone UITextView - regexARC-enabled TWTweetComposeViewController memory leak - objective-cHow to pass a string literal ("~ / test / foo") to the mkdir function in C programming? - cPolygon drawing in OpenCV? - c ++How to compare two lists of arrays? - arrayslightweight, polyglot alternative to JMX? - javaHow can I confuse a string in a C ++ binary? - c ++How to plot a 3D surface in MATLAB? - graphDiacritical Combination Properties - unicodeAll Articles