필터 지우기
필터 지우기

selecting certain elements of an array

조회 수: 29 (최근 30일)
SSG_newbiecoder
SSG_newbiecoder 2017년 12월 26일
편집: Kodavati Mahendra 2017년 12월 26일
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

답변 (1개)

Kodavati Mahendra
Kodavati Mahendra 2017년 12월 26일
편집: Kodavati Mahendra 2017년 12월 26일
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 |

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by