필터 지우기
필터 지우기

How to return a specific index of a vector?

조회 수: 6 (최근 30일)
Joe Cousins
Joe Cousins 2021년 8월 26일
댓글: Walter Roberson 2021년 8월 26일
The problem I have here is that I want to return the index of the next point. If I input find_next_point(1, [6 7 8 9], x, y) the code returns everything I want except it displays that the next point is point 1 rather than 6 (which is the next point). I understand that this is just displaying the index from the vector [6 7 8 9] and returning that it is the first number in the vector, but how can I make it display the actual number instead e.g. 6 Hope this makes sense
function [next_point, distance] = find_next_point(current_point, points_to_check, x, y)
distance = compute_distance(current_point, points_to_check, x, y) %find all distances in array
[smallest_distance, next_point] = min(distance) %find smallest of these distances
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 26일
current_point(next_point)
  댓글 수: 4
Joe Cousins
Joe Cousins 2021년 8월 26일
Thank you, it's working. I had to change it to:
next_point = points_to_check(idx)
since the input current_point was an array of 1 element and I was getting an error of index exceeds the number of array elements.
Really appreciate your time and help!
Walter Roberson
Walter Roberson 2021년 8월 26일
Oh, right, that makes sense.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by