function i = locate(x, z, g) # Usage: i = locate(x, z, g) # # This function finds i such that z is in [x(i), x(i+1)] # # inputs: # x coordinates, x(1) left+1) # x(left) <= z <= x(right) mid = floor((left+right)/2); if (z < x(mid)) right = mid; else left = mid; endif endwhile i = left; endif endfunction # locate