Is it a precision mistake? Creating a vector goes wrong.

2 ビュー (過去 30 日間)
Ioannis Nemparis
Ioannis Nemparis 2017 年 11 月 7 日
コメント済み: Guillaume 2017 年 11 月 7 日
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
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
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 件のコメント
Ioannis Nemparis
Ioannis Nemparis 2017 年 11 月 7 日
Still this does not explain why round(min) or fix(min) would not work
Guillaume
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 ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by