Mex: useful comparing float values?

3 visualizzazioni (ultimi 30 giorni)
mick strife
mick strife il 4 Mag 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! :)

Risposta accettata

Image Analyst
Image Analyst il 4 Mag 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 Commenti
Image Analyst
Image Analyst il 4 Mag 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 il 5 Mag 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! :-)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by