Filter löschen
Filter löschen

selecting certain elements of an array

27 Ansichten (letzte 30 Tage)
SSG_newbiecoder
SSG_newbiecoder am 26 Dez. 2017
Bearbeitet: Kodavati Mahendra am 26 Dez. 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

Antworten (1)

Kodavati Mahendra
Kodavati Mahendra am 26 Dez. 2017
Bearbeitet: Kodavati Mahendra am 26 Dez. 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 |

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by