Boolean False when it should be True

8 views (last 30 days)
Sabrina Spracklen
Sabrina Spracklen on 20 Apr 2021
Commented: Jonas on 20 Apr 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 Comment
Jonas
Jonas on 20 Apr 2021
maybe the difference is very small and not within 3 digits. did you try to subtract the two values, is the result 0?

Sign in to comment.

Answers (1)

Matt J
Matt J on 20 Apr 2021
Edited: Matt J on 20 Apr 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

Products

Community Treasure Hunt

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

Start Hunting!