필터 지우기
필터 지우기

Why is the out-printed string displaying the wrong values?

조회 수: 2 (최근 30일)
The Merchant
The Merchant 2019년 12월 4일
댓글: Adam Danz 2020년 1월 16일
The code of the fprintf-part:
coordPoints = [convexHull,coordsConvex].';
fprintf('convex hull points:');
fprintf(' %d (%d %d),',coordPoints(:,1:end - 1))
fprintf(' and %d (%d %d).\n',coordPoints(:,end))
The current output:
convex hull points: 16 (0 3), 13 (0 0), 11 (6 0), 8 (8 0), 5 (8 6), 1 (0 8), and 18 (0 4).
The desired output:
convex hull points: 16 (-10 3), 13 (-9 -5), 11 (6 -10), 8 (8 -7), 5 (8 6), 1 (-7 8), and 18 (-10 4).
It is clearly caused by the negative values, but I can't seem to figure out how exactly.
The variable coordsConvex
-10 3
-9 -5
6 -10
8 -7
8 6
-7 8
-10 4
The variale coordPoints
16 13 11 8 5
0 0 6 8 8
3 0 0 0 6
  댓글 수: 5
Rena Berman
Rena Berman 2020년 1월 16일
(Answers Dev) Restored edit
Adam Danz
Adam Danz 2020년 1월 16일
Thanks, Rena!

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 12월 4일
편집: Adam Danz 2019년 12월 4일
This line below changes the values of convexHull.
coordPoints = [convexHull,coordsConvex].';
To prevent that, convert to double
coordPoints = [double(convexHull),coordsConvex].';
% ^^^^^^^
fprintf('convex hull points:');
fprintf(' %d (%d %d),',coordPoints(:,1:end - 1))
fprintf(' and %d (%d %d).\n',coordPoints(:,end))
Result
convex hull points: 16 (-10 3), 13 (-9 -5), 11 (6 -10), 8 (8 -7), 5 (8 6), 1 (-7 8), and 18 (-10 4).
  댓글 수: 2
Adam Danz
Adam Danz 2019년 12월 4일
편집: Adam Danz 2019년 12월 4일
Glad we finally got there. ;) That answer would have been impossible without the code which came after a bit of dialog.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Bounding Regions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by