if statement logical error

1 次查看(过去 30 天)
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 个评论
Junaid
Junaid 2011-12-1
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2011-12-1
Your data is not what you think it is. The 0.2421 entry is triggering the problem.
  3 个评论
Walter Roberson
Walter Roberson 2011-12-1
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.
Duaa
Duaa 2011-12-1
thank you Mr.Walter Roberson
for your help, problem solved

请先登录,再进行评论。

更多回答(1 个)

Junaid
Junaid 2011-12-1
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'.
  1 个评论
Duaa
Duaa 2011-12-1
hello Mr.Junaid
I think the problem is in s or e
>> i=imread('cancer1.png');
>>i=irgb2gray(i);
>> glcm = graycomatrix(i);
>> stats=graycoprops(glcm,{'contrast','homogeneity','correlation','energy'});
>> stats=struct2cell(stats);
>> s=cell2mat(stats);
>> e=entropy(i);
image i is uploaded here
http://imageshack.us/photo/my-images/828/cancer1.png/
you can check error after using if statement

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by