フィルターのクリア

Mex: useful comparing float values?

3 ビュー (過去 30 日間)
mick strife
mick strife 2013 年 5 月 4 日
Hello,
i have a mex-script which returns to matlab some float-values. As i have to check the returning data i have also a c-script with the same function as the mex-script. When i want to compare the data i noticed that the matlab-data and c-data have different number of decimal places although both are using float(single) as datatype.
As i am quite a beginner in c and matlab i am not sure how to solve this usefully. thx for any advise! :)

採用された回答

Image Analyst
Image Analyst 2013 年 5 月 4 日
You have to check if they are within some tolerance of each other. Please see the FAQ. http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F . It gives you some code you can use.
  3 件のコメント
Image Analyst
Image Analyst 2013 年 5 月 4 日
I think c can show to more than 6 or 7 decimal places. I think you misunderstood. Maybe what they were saying was that single precision numbers are accurate only out to the 6 or 7th decimal place, and that if you show anything after that, it could be just garbage. Those are two different things to say.
Yes, I think using a tolerance, like they do in the FAQ I referred you to, is a good solution.
mick strife
mick strife 2013 年 5 月 5 日
Thx "image analyst". Yes, i misunderstood that. He told me that float is only accurate with 6,7 decimal places and if i want more decimal places i should use an other data type.
thx for your advice! :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by