Ignoring If statements error

조회 수: 3 (최근 30일)
Adam
Adam 2014년 5월 26일
댓글: Adam 2014년 5월 26일
Hi I am having trouble with my selection of if statements to sort out a minvalue grab from my array. In previous code the min function incorrectly grabed the wrong value that wasnt even close to being the minimum value in the array. To try and correct this mistake I made a series of If Statements that account for the changing poitions of the value real value trying to be detected through ranges. Xep is the value that is stable and doesnt have a problem with finding its measured location. Xbp is the error problem. The two variables should be no more than pixels away from each other and when they are this error occurs and I try to fix it with these If Statements:
if(20 <= (Xep - Xbp))
if(450<=Xep<=500)
j=450;
while DC1(1,j) ~= min(DC1(:,450:500)),DC1(1,j);
Xbp = j;
j=j+1;
end
end
if(350<=Xep<=449)
j=350;
while DC1(1,j) ~= min(DC1(:,350:450)),DC1(1,j);
Xbp = j;
j=j+1;
end
end
if(250<=Xep<=349)
j=250;
while DC1(1,j) ~= min(DC1(:,250:349)),DC1(1,j);
Xbp = j;
j=j+1;
end
end
if(150<=Xep<=249)
j=150;
while DC1(1,j) ~= min(DC1(:,150:249)),DC1(1,j);
Xbp = j;
j=j+1;
end
end
if(1<=Xep<=149)
j=1;
while DC1(1,j) ~= min(DC1(:,1:149)),DC1(1,j);
Xbp = j;
j=j+1;
end
end
end
Xbp: 45 Xep: 417
I am unsure why this error is occuring as my If Statements seem to make sense to be. But when the code runs into the error with values like the two above, nothing happens and the code just skips over the If Statements like their not there.
Can someone please help me with this?

채택된 답변

Jos (10584)
Jos (10584) 2014년 5월 26일
the expression
A < B < C
will be interpreted in matlab as
  • 1 < C, when A is smaller than B, or
  • 0 < C, when A is not smaller then B
This will be true or false depending on the value of C.
You (most likely) want
A < B AND B < C
which is notated in matlab as
A < B && B < C
  댓글 수: 1
Adam
Adam 2014년 5월 26일
Thank you very much for the help, I knew it was something silly. I hadnt worked with matlab for a while so some of the notation was causing me problems.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by