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 Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by