Filter löschen
Filter löschen

Why are the inequality expressions not evaluated correctly?

2 Ansichten (letzte 30 Tage)
My code is: grid is just a 5x6 matrix, so is visited.
neighbor=[3 4]
if((neighbor(1)>0) && (neighbor(1)<size(grid,1)+1) && (neighbor(2)>0) && (neighbor(2)<size(grid,2)+1) && (visited(neighbor(1),neighbor(2)==-1)))
Matlab gives the following error: Operands to the and && operators must be convertible to logical scalar values.
What's going wrong? I tried to debug step by step but could not figure out the mistake.

Akzeptierte Antwort

Image Analyst
Image Analyst am 2 Feb. 2015
Perhaps you meant:
if((neighbor(1)>0) && (neighbor(1)<size(grid,1)+1) && (neighbor(2)>0) && (neighbor(2)<size(grid,2)+1) && (visited(neighbor(1),neighbor(2))==-1))

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by