if statement logical error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am working with image processing toolbox and I keep getting the wrong results the main idea is that I calculate some features form any image and store these values in a row vector (s), and a variable (e) then I compare the list of results with range values in the if statement the problem is it keeps getting the else part even if the if part is right??
this is the if statement part:
if(s(1)<=0.1649 && s(1)>=0.1062)...
&&(s(2)<= 0.9737&& s(2)>=0.9620)...
&&(s(3)<=0.3081 && s(3)>=0.2421)...
&& (s(4)<=0.9501 && s(4)>=0.9278) && (e<=5.4846 && e>=5.1281)
results='Positive Results';
else
results='Negative Results';
end
assume s and e were input as follows
s=[0.1630 0.9710 0.2421 0.9286];
e=5.4846;
please help,thank u in advance..
1 comentario
Junaid
el 1 de Dic. de 2011
Dear friend. I don't see any logical error. Output is Result = 'Positive Results'. This is what it should be as all conditions are true.
Respuesta aceptada
Walter Roberson
el 1 de Dic. de 2011
Your data is not what you think it is. The 0.2421 entry is triggering the problem.
3 comentarios
Walter Roberson
el 1 de Dic. de 2011
tol is a number you make up based upon your knowledge of the magnitude of the errors in the calculation.
For example, you might choose
tol = 16 * eps(max(abs([a,b])));
if you wanted to give room for about 4 rounding errors in the calculation.
Sometimes you need much higher tolerances: if you have divisions by numbers that are less than 1, then a single bit difference in the original number can get magnified to considerably.
The technique of determining how small changes in inputs affect the outputs is generally known as "numeric analysis". Sometimes the calculations are simple, but there are counter-intuitive proofs that errors can become arbitrarily large as you *increase* precision.
Más respuestas (1)
Junaid
el 1 de Dic. de 2011
Dear when I execute your code, i get the if part not else part. I also checked your all conditions and all conditions are true.
If you are confuse in any part you can check all condition one bye one like this.
s(4)<=0.9501 && s(4)>=0.9278
it should output 1. then you can debug it yourself. So far your all conditions are true and you get Result = ' Positive Results'.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!