If statement with multiple conditions

55 visualizaciones (últimos 30 días)
Robert
Robert el 16 de Abr. de 2013
Comentada: Maryam ARIF el 24 de Feb. de 2019
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.

Respuesta aceptada

Friedrich
Friedrich el 16 de Abr. de 2013
Editada: Friedrich el 16 de Abr. de 2013
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 comentarios
Maryam ARIF
Maryam ARIF el 24 de Feb. de 2019
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 el 24 de Feb. de 2019
plz give me a answer of this question

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by