Borrar filtros
Borrar filtros

How to pick next value from vectors based on a condition?

2 visualizaciones (últimos 30 días)
Evans Gyan
Evans Gyan el 13 de Mayo de 2019
Comentada: Evans Gyan el 14 de Mayo de 2019
Assuming i have a vector
A = [ 7.7 213.1 9.5 227.5 12.5 6.8 100.8 5.3 7.2 99.4]
I want to pick a value that is maximum and is greater or equal to the index 5.
In this case my answer would be 100.8 and is of index 7.
Thanks in advance

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 13 de Mayo de 2019
m = 5;
[value,ii] = max(A(m:end));
index = ii + m - 1;
  2 comentarios
Evans Gyan
Evans Gyan el 13 de Mayo de 2019
Thanks a million.
Evans Gyan
Evans Gyan el 14 de Mayo de 2019
If i want to pick say three highest values from the vector A together with their index, How do i go by it? In this case the values to be selected will be
val = 227.5 213.1 100.8
idx = 4 2 7

Iniciar sesión para comentar.

Más respuestas (1)

Alex Mcaulley
Alex Mcaulley el 13 de Mayo de 2019
max(A(5:end))

Categorías

Más información sobre Matrix Indexing 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