Borrar filtros
Borrar filtros

How to find the index in array?

1 visualización (últimos 30 días)
Meshooo
Meshooo el 3 de Ag. de 2016
Comentada: Meshooo el 4 de Ag. de 2016
Dear all,
I have the following array A = [0;0;0;0;0;0;1;1;;0;0;0;0];
I want to find the right and left index of the 1's? In this case
Left_A = 7
Right_A = 8
In another situations, A = [0;0;0;0;0;0;1;0;0;1;0;0;0];
Left_A = 7
Right_A = 10
Any idea how to do that? Thank you very much.
Meshoo

Respuesta aceptada

Adam
Adam el 3 de Ag. de 2016
Left_A = find( A == 1, 1 );
Right_A = find( A == 1, 1, 'last' );
  1 comentario
Meshooo
Meshooo el 4 de Ag. de 2016
That works very well. Thank you very much.

Iniciar sesión para comentar.

Más respuestas (0)

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