Equals numbers returns not equal

4 visualizaciones (últimos 30 días)
SAFA YILDIRIM
SAFA YILDIRIM el 5 de Mayo de 2020
Comentada: SAFA YILDIRIM el 5 de Mayo de 2020
Hello I have a code like below:
figure
arr = [0.0207,0.6371,0.7504,0.1585,0.3091,0.5112];
for i=1:6
item = arr(i);
image = NewImage;
for r=1:row
for c=1:column
temp = image(r,c,1);
if item ~= temp
image(r,c,:) = 0;
end
end
end
subplot(3,2,i),imshow(image);
end
temp variable and item are both equal to 0.0207 but program flow enters if block. What is the problem?

Respuesta aceptada

Clemens Gersch
Clemens Gersch el 5 de Mayo de 2020
Editada: Clemens Gersch el 5 de Mayo de 2020
Are you sure that they are exactly the same?
Try
format long
and then display your values again. I guess that temp is only roughly 0.0207 and not exactly.
If that is the reason for your problem, you can try the following:
if item ~= round(temp,4)
  1 comentario
SAFA YILDIRIM
SAFA YILDIRIM el 5 de Mayo de 2020
Thank you so much. It solved the problem :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by