필터 지우기
필터 지우기

Work with Array

조회 수: 1 (최근 30일)
Mohammad
Mohammad 2012년 3월 9일
Hello Is there any function to elimiate automomatically member with negetive index? for example:
i=1:10 y(i)=x(i-2);
it's a simple example. could you please help me? thank you.

채택된 답변

Jacob Halbrooks
Jacob Halbrooks 2012년 3월 9일
Logical indexing can be a good way to remove or manipulate elements in an array. In your case, let's say you have an array of indices, some of which are invalid (i.e. less than 1):
ind = [1:10]-2
Create a new array of indices with only valid values:
validInd = ind(ind >= 1)
If you wanted to instead replace illegal index values with a number such as 1, you could do this:
validInd = ind;
validInd(validInd< 1) = 1

추가 답변 (1개)

PHAM
PHAM 2012년 3월 9일
maybe we can try for i=2:12 y(i+2) = x(i)
  댓글 수: 1
Mohammad
Mohammad 2012년 3월 9일
Thank you . i said it's a simple example but in real program i can't do that.
if you know any function that put zero for illegal index , for example return 0 for x(-1), please help me.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by