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

조회 수: 9 (최근 30일)
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

채택된 답변

KSSV
KSSV 2021년 3월 31일
You have straight functions to achieve this. REad about ismember and knnsearch.
  댓글 수: 2
Raife Jones
Raife Jones 2021년 3월 31일
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 2021년 3월 31일
x = [2,7,3,5,-2] ;
y = [1,5,1,5,-2] ;
[c,ia] = ismember(x,[2 3 5]) ;
y(c)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by