"Or Statement in And statement" using if operator

조회 수: 74 (최근 30일)
Doris
Doris 2016년 5월 30일
편집: per isakson 2017년 11월 24일
Hello everyone,
I have a very simple question....and I have been working on it for some time but cannot figure it out. I try to write the statement that condition 1 : Test(i-1) or Test(i-2) =0, condition 2: Test(i+1) or Test(i+2) =0, when condition 1 and condition 2 are true then the statement is true. I tried to write the code but it did not work at all.
for i = 3:N-2
if Test(i-1)==0||Test(i-2)==0 && Test(i+1)==0||Test(i+2)==0
end
end
Thanks for the help in advance :)

채택된 답변

Stephen23
Stephen23 2016년 5월 30일
편집: Stephen23 2016년 5월 30일
You need to use brackets to group the logical statements together:
if (A || B) && (C || D)
Otherwise the operator precedence rules gives the order in which they are evaluated.
Note that you should not use i (or j) for loop variable names, as these are names of the inbuilt imaginary unit.
  댓글 수: 5
Stephen23
Stephen23 2016년 5월 31일
편집: Stephen23 2016년 5월 31일
In my last comment I explained why that test probably failed (because the value isn't really zero). The solution to this is also explained in my last comment.
If you upload a .mat file with those value then I can check the values, and show you how you can compare them in a more robust manner.
Doris
Doris 2016년 6월 2일
Thank you so much. I have solved this problem. The float number was the biggest problem and I also wrote the if statement in wrong way.

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

추가 답변 (1개)

arief hidayat
arief hidayat 2017년 11월 24일
편집: per isakson 2017년 11월 24일
hi i got same issue when i running script as below :
if ((rate ~= rate_tx || (Nbpsc ~= Nbpsc_tx) || (psdu_byte ~= psdu_byte_tx)))
Percounter = 1;
noviterbi_Y = [];
PSDU = [];
return ;
else
Percounter = 0;
help me please

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by