Is it a precision mistake? Creating a vector goes wrong.
2 ビュー (過去 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!