Mex: useful comparing float values?

3 vues (au cours des 30 derniers jours)
mick strife
mick strife le 4 Mai 2013
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! :)

Réponse acceptée

Image Analyst
Image Analyst le 4 Mai 2013
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 commentaires
Image Analyst
Image Analyst le 4 Mai 2013
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 le 5 Mai 2013
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! :-)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by