Boolean False when it should be True

조회 수: 12 (최근 30일)
Sabrina Spracklen
Sabrina Spracklen 2021년 4월 20일
댓글: Jonas 2021년 4월 20일
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
Jonas
Jonas 2021년 4월 20일
maybe the difference is very small and not within 3 digits. did you try to subtract the two values, is the result 0?

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2021년 4월 20일
편집: Matt J 2021년 4월 20일
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

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by