If statement with multiple conditions

조회 수: 58 (최근 30일)
Robert
Robert 2013년 4월 16일
댓글: Maryam ARIF 2019년 2월 24일
I am processing an image in which I have found a blob and I want to compare the location of that blob to the location of a blob in another image using these lines of code:
for j=1:10
if ((blob(j,4)-50)<centroid(1)<(blob(j,4)+50))
if ((blob(j,5)-50)<centroid(2)<(blob(j,5)+50))
%more processing code
end
end
end
The variable 'blob' is a table of previous blobs that have been found with their x location in column 4 and the y location in column 5. The code should cycle through the 10 other voids in the table and if their location is within +/- 50 pixels to the new void then some further code is run.
At the moment these if statements seem to be taken as true regardless of what centroid values I put in and I can't see why.
Note that centroid(1) and centroid(2) have been found using regionprops.

채택된 답변

Friedrich
Friedrich 2013년 4월 16일
편집: Friedrich 2013년 4월 16일
Hi,
this ((blob(j,4)-50)<centroid(1)<(blob(j,4)+50)) wont work as you might think it will. You need to split it up into
((blob(j,4)-50)<centroid(1)) && (centroid(1)<(blob(j,4)+50))
For the answer to why is that needed see the second half of my answer here:
  댓글 수: 3
Maryam ARIF
Maryam ARIF 2019년 2월 24일
write a matlab program which takes a number x from user and display the value of the following function f(x)
f(x)= x/a(x) if x<=-1
sqrtx/b(x) if-1<x<10
x^3/2/r(x) otherwise
where a(x)=1 if cosx>0
-1 otherwise
b(x)=1 if sinx>0
-1 otherwise
r(x)=1 ifcosxsinx>0
-1 otherwise
Maryam ARIF
Maryam ARIF 2019년 2월 24일
plz give me a answer of this question

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by