Is it a precision mistake? Creating a vector goes wrong.
조회 수: 5 (최근 30일)
이전 댓글 표시
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
Adam
2017년 11월 7일
You haven't included the code where you tried ceil or fix which are the obvious solutions (or round or floor)
답변 (1개)
John D'Errico
2017년 11월 7일
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
Guillaume
2017년 11월 7일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!