필터 지우기
필터 지우기

if statement within loop

조회 수: 1 (최근 30일)
Matlabbey
Matlabbey 2012년 8월 27일
hi all
i been trying to solve this problem for some time. i try before but i got close but not all the way. here is example
x= [ 0 2 4 6 8 10] % i use this vector for intervals as such:
%[0 2 4 6 8]
%[2 4 6 8 10]
y = [ 0.96 0.49 0.80 0.14 0.42 0.92 0.79 0.96 0.66 0.04]; %these are data values
here is my loop that dont work:
for m = 1:length(x)-1
if x(i) < y ~= 0 <x(i+1)
new1 = [x(i)];
new2 = [x(i+1)];
end
end
my if statement is poor but i dont know how to make it. in words i want to do this: if y does not equal to zero in the interval x(i), x(i+1) i want to keep x(i) and x(i+1) for the new1 and new2. but if y is equal to zero in that interval, than those values dont move to new1 and new1. please any suggestions i can try to explain better if asked but i hope its clear!!! thanks you!!!!!
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 8월 27일
y is not 0 anywhere in your sample data, and does not cross 0 either, so there does not seem to be any point in doing the test.
Matlabbey
Matlabbey 2012년 8월 27일
hi,
i just use this as a example. but thanks you for your comment!!

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 8월 27일
if any (y(x(i) : x(i+1)) == 0)
However, one of your x is 0, and y(0) does not exist. Please clarify which endpoints "in the interval" includes.
  댓글 수: 2
Matlabbey
Matlabbey 2012년 8월 28일
thanks for response, but i actually ran into problem of y(0)!!
some interval begin at 0, is there no way to include 0 in the statement?
Albert Yam
Albert Yam 2012년 8월 28일
y(0) problem is NOT, y=0 at some point. y(0) means the zeroth element of y, which does not exist. Matlab indexing starts at one. So the first element of y is y(1) = some_value.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by