Find indexes according to a value in array

2 visualizaciones (últimos 30 días)
Gabriel Melendez
Gabriel Melendez el 30 de Mzo. de 2020
Editada: the cyclist el 30 de Mzo. de 2020
Hello everybody,
I am trying to find array indexes in which a certain value is found.
For example, I have the next array with 10 elements.
A = [2 4 6 8 10 12 14 16 18 20]
Now, I have a value x = 11.
x = 11
According to x value, I would like to get the indexes 5 and 6 corresponding to the array values 10 and 12, in which 11 is found.
I tried to solve it as next:
find((A>x) & (A<=x))
However, it returns an empty vector.
I hope you can help me.
Thank you very much!

Respuesta aceptada

the cyclist
the cyclist el 30 de Mzo. de 2020
Editada: the cyclist el 30 de Mzo. de 2020
Dare I say obviously, A can't obey both the conditions simultaneously. You need to find the indices separately.
[find(A<=x,1,'last') find(A>x,1,'first')]

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by