How can I get a position of a value from an array, and the same position in another array?

9 views (last 30 days)
How can I get a position of a single value from an array, and the same position in another array?
function [next_point, calculated_L] = pick_next_point(x_c, y_c, points_to_check, x, y)
next_point = points_to_check; % sets next_point to the points_to_check
L = sqrt((x_c - x).^2 + (y_c - y).^2); % grabs the distance between the current point and all given points
calculated_L = L(points_to_check); % grabs the L of the points that haven't been visited
calculated_L = min(calculated_L); % takes the smallest vector (smallest distance)
disp(calculated_L);
disp(next_point);
end
with:
x_c = 2
y_c = -1
x = [2,7,3,5,-2]
y = [1,5,1,5,-2]
points_to_check = [2,3,5]
I want to get the position of the second value in "calculated_L = L(points_to_check);" (postion of value will change) (those values being == [7,3,-2])
and then want to find the value in the same position in points_to_check

Accepted Answer

KSSV
KSSV on 31 Mar 2021
You have straight functions to achieve this. REad about ismember and knnsearch.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!