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)
Mostrar comentarios más antiguos
Raife Jones
el 31 de Mzo. de 2021
Comentada: KSSV
el 31 de Mzo. de 2021
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
0 comentarios
Respuesta aceptada
KSSV
el 31 de Mzo. de 2021
You have straight functions to achieve this. REad about ismember and knnsearch.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!