Ignoring If statements error

1 visualizzazione (ultimi 30 giorni)
Adam
Adam il 26 Mag 2014
Commentato: Adam il 26 Mag 2014
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?

Risposta accettata

Jos (10584)
Jos (10584) il 26 Mag 2014
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 Commento
Adam
Adam il 26 Mag 2014
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by