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

5 visualizaciones (últimos 30 días)
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

Respuesta aceptada

KSSV
KSSV el 31 de Mzo. de 2021
You have straight functions to achieve this. REad about ismember and knnsearch.
  2 comentarios
Raife Jones
Raife Jones el 31 de Mzo. de 2021
How would you use knnsearch in my case?
and doesn't ismember just determines if one array has the same numbers as the second?
KSSV
KSSV el 31 de Mzo. de 2021
x = [2,7,3,5,-2] ;
y = [1,5,1,5,-2] ;
[c,ia] = ismember(x,[2 3 5]) ;
y(c)

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by