Borrar filtros
Borrar filtros

How to find vector components limiting a value?

1 visualización (últimos 30 días)
osminbas
osminbas el 2 de Abr. de 2012
Hello,
Say A=[2;4;7;9;11;15].
How do you find the components (indices) of A which are limiting a value, say k=10?
In this case, it is easy to see that A(4) and A(5) are the limiting components, i.e, k is in between 9 and 11: A(4)<k<A(5). My actual A is much bigger.
Thanks!

Respuesta aceptada

the cyclist
the cyclist el 2 de Abr. de 2012
If your vector is guaranteed to be in sorted order, as in your example, then
max(find(a<k))
and
min(find(a>k))
will give the two limits.
You might want to make one of those include the equality, in case it might be exactly equal to the border. Also, you really only need to calculate, say, the lower limit, and then the other limit is just the next index.
Finally, you might need to consider what to do if all values in the vector are above (or below) the value of k.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by