Boolean False when it should be True

12 vues (au cours des 30 derniers jours)
Sabrina Spracklen
Sabrina Spracklen le 20 Avr 2021
Commenté : Jonas le 20 Avr 2021
Something is wrong with my boolean being rendered: x1=find(data(:,1)==dom(8,2)) . It returns as false but dom(8,2)=8.3 and data(416,1)= 8.3000
  • I import the 1250x3 matrix data correctly and the 9x5 matrix dom correctly.
  • x2, x3, and x4 are processed correctly
  • I tested in the command line that 8.3000==8.3 (returned as true)
  • I tried str2num(data(416,1)) just in case, didn't work
  • data(:,1)==dom(i,2) is a 0x1 double
My work is really messy so I don't want to post the whole code but I can if someone thinks it might help. I have 9 different data sets represented by i and this code works for a majority of them.
%i represents the dataset loaded into data and the row for dom which is short for domain because I hand selected start and stop points for each dataset
i=8;
x1=find(data(:,1)==dom(i,2));
x2=find(data(:,1)==dom(i,3));
x3=find(data(:,1)==dom(i,4));
x4=find(data(:,1)==dom(i,5));
Also for reference:
>> 8.3000==8.3
ans =
logical
1
>> data(416,1)
ans =
8.3000
>> data(416,1)==8.3
ans =
logical
0
Thank you in advance to anyone who had the patience to look at this
  1 commentaire
Jonas
Jonas le 20 Avr 2021
maybe the difference is very small and not within 3 digits. did you try to subtract the two values, is the result 0?

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 20 Avr 2021
Modifié(e) : Matt J le 20 Avr 2021
dom(8,2) is only 8.3000 to 4 decimal places. You cannot see the differences beyond the 4th decimal unless you use
>> format long

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by