Finding a value, index which lies between 2 points in an array

조회 수: 1 (최근 30일)
Yash Runwal
Yash Runwal 2020년 9월 10일
댓글: Yash Runwal 2020년 9월 10일
Hello fellow MATLAB users,
I am currently writing a MATLAB function for which I need some help.
For example:
I have an array and a value:
X = [0, 10, 20];
value = 17;
I need to find the indices of the X in which the value lies:
Here the answer will be X[2] and X[3].
But I am not sure how to do this. I would really appreciate any help I can get.
Thank You.

채택된 답변

Matt J
Matt J 2020년 9월 10일
i=discretize(value,X)
j = i+1
X([i,j])
  댓글 수: 1
Yash Runwal
Yash Runwal 2020년 9월 10일
Actually both of the answers work. I am gonna have to look up the functions discretize and interp1

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

추가 답변 (1개)

Matt J
Matt J 2020년 9월 10일
편집: Matt J 2020년 9월 10일
i = interp1(X,1:numel(X),value,'previous')
j = i+1
X([i,j])

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by