Is it a precision mistake? Creating a vector goes wrong.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am getting a very strange bug namely:
bboxMxY = max(UVW(curPoints(logic),2));
bboxMxZ = max(UVW(curPoints(logic),3));
bboxMnY = min(UVW(curPoints(logic),2));
bboxMnZ = min(UVW(curPoints(logic),3));
Ycor = bboxMnY:bboxMxY;
Zcor = bboxMnZ:bboxMxZ
There is nothing fancy taking place here. Just 2 mins and 2 maxes. The mins are -2.000 and -3.000. And the maxes are 2 and 3.000. So unfortunately when I do
Ycor = bboxMnY:bboxMxY
I get the equivalent of -2:1 and not -2:2. Why is this happening? I tried to use ceil,fix or add an eps but they do not work. What is really the reason behind this, and how can I bypass it?
1 commentaire
Adam
le 7 Nov 2017
You haven't included the code where you tried ceil or fix which are the obvious solutions (or round or floor)
Réponses (1)
John D'Errico
le 7 Nov 2017
Your numbers are not true integers.
format short
x = [1.999999 2.0000001 2.99999 3.000000001]
x =
2.0000 2.0000 3.0000 3.0000
See that even though it looks like x is the vector [2 2 3 3] we know it is not. In your case, you only think your data ranges between integer limits, it does not.
2 commentaires
Guillaume
le 7 Nov 2017
fix rounds towards 0, so fix(-1.9999) will return -1, not -2.
round should work though and so would:
Ycor = floor(bboxMnY):ceil(bboxMxY);
If it does not, then attach sample data that reproduces the problem.
Voir également
Catégories
En savoir plus sur Logical 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!