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 Center および File ExchangeCell Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by