selecting certain elements of an array

56 visualizaciones (últimos 30 días)
SSG_newbiecoder
SSG_newbiecoder el 26 de Dic. de 2017
Editada: Kodavati Mahendra el 26 de Dic. de 2017
hello, I have an array of 200 elements. I'm trying to apply certain conditions to the elements in the array. I have to select 20 elements to the left and right of the first element that is greater than 0. But if this element doesn't have 20 elements to say, the left side(for example, say 10th element is greater than zero), still I have to choose how much ever values there are to the left. how can I do this

Respuestas (1)

Kodavati Mahendra
Kodavati Mahendra el 26 de Dic. de 2017
Editada: Kodavati Mahendra el 26 de Dic. de 2017
s = -100:100;
A = find(s>0);
s(max(A(1)-20,1):A(1)+20)
|Lets say S is the array of 200 elements.
Use find function to find all the values that satisfy your condition (value>0),
A array has indices of all values that are greater than 0 in S.
In case of 10th element greater than 0, I used max(A(1)-20,1) to make sure that 1 start from the first element
Hope this helps, I am also a newbie coder :-P |

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by