If I understand correctly, this expression
minloc(abs(a-value/b(idx2)))
will return the the index into a
of the first occurrence of the value in a
which minimises the difference. I expect that the compiler will write code to scan all the elements in a
so this may not be faster in execution than a search which takes advantage of the knowledge that a
and b
are both sorted. In compensation, this is much quicker to write and, I expect, to debug.