MATLAB: How to determine what grid cell a given point is in

gridgriddatapoint

I apologize if this question has been asked before but I have looked and cannot find an answer.
Lets say I have a grid with x-vector [1:10] and y-vector [1:10]. And now I have the point (3.994, 7.554).
Is there an easy way to determine which grid cell this point lies in? I am currently solving the problem with for loops to find the nearest x- and y-line to the point. But I am sure there is an embedded function which addresses the problem.
Any help is appreciated. Cheers

Best Answer

One possibility:
x_vector = [1:10];
y_vector = [1:10];
point = [3.994, 7.554];
x_grid = find(x_vector <= point(1), 1, 'last');
y_grid = find(y_vector <= point(2), 1, 'last');
x_grid = [x_grid x_grid+1]
y_grid = [y_grid y_grid+1]
The output are the final values of ‘x_grid’ and ‘y_grid’