Is it a precision mistake? Creating a vector goes wrong.
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Adam
el 7 de Nov. de 2017
You haven't included the code where you tried ceil or fix which are the obvious solutions (or round or floor)
Respuestas (1)
John D'Errico
el 7 de Nov. de 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 comentarios
Guillaume
el 7 de Nov. de 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.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!