MATLAB Answers

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

6 views (last 30 days)
The Merchant
The Merchant on 4 Dec 2019
Commented: Adam Danz on 16 Jan 2020
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 Comments

Show 2 older comments
Adam Danz
Adam Danz on 15 Dec 2019
@ The Merchant, the majority of help this forum provides is by users searching for pre-existing questions and finding answers. Lots of volunteers have invested their time into answering questsions and when the content of those questions is removed, the investment of that time turns out to be a waste. It's disrespectful to ask for help and then eliminate the utility of the time they gave you.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 4 Dec 2019
Edited: Adam Danz on 4 Dec 2019
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 Comments

Adam Danz
Adam Danz on 4 Dec 2019
Glad we finally got there. ;) That answer would have been impossible without the code which came after a bit of dialog.

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by