If statement with multiple conditions

57 visualizzazioni (ultimi 30 giorni)
Robert
Robert il 16 Apr 2013
Commentato: Maryam ARIF il 24 Feb 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.

Risposta accettata

Friedrich
Friedrich il 16 Apr 2013
Modificato: Friedrich il 16 Apr 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 Commenti
Maryam ARIF
Maryam ARIF il 24 Feb 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 il 24 Feb 2019
plz give me a answer of this question

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by