if statement logical error

조회 수: 2 (최근 30일)
Duaa
Duaa 2011년 12월 1일
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