Mex: useful comparing float values?

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Introduction 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