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

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 件のコメント

Adam Danz
Adam Danz 2019 年 12 月 4 日
The only inputs to your fprintf() commands are values from coordPoints but your desired output includes values that aren't from that set such as -10, -9, all of the negative values....
The Merchant
The Merchant 2019 年 12 月 4 日
When my list is
coordsInput = [ % Points
3 12 % 1
10 8 % 2
11 14 % 3
13 16 % 4
9 19 % 5
1 15 % 6
2 6 % 7
6 1 % 8
12 5 % 9
16 7 % 10
14 17 % 11
19 18 % 12
];
it does work, also with both on coordsInput.
Its very weird.
I think it goes wrong when coordsPoint is established, but I dont know why
Adam Danz
Adam Danz 2019 年 12 月 15 日
@ 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.
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 日

0 投票

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 件のコメント

The Merchant
The Merchant 2019 年 12 月 4 日
thanks!
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 件)

カテゴリ

ヘルプ センター および File ExchangeFinancial Toolbox についてさらに検索

質問済み:

2019 年 12 月 4 日

コメント済み:

2020 年 1 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by