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

5 次查看(过去 30 天)
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 个)

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 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by