MATLAB Answers

How to limit rounding in matrix division

20 ビュー (過去 30 日間)
Maine MacConville
Maine MacConville 2016 年 3 月 15 日
回答済み: Chris Turnes 2016 年 3 月 15 日
I've a 2D matrix with values ranging from about 40 to 100. I'm dividing each entry value by 98 and for some reason, it's rounding my answers to 0 and 1. How can I limit this and get more decimal places? Or even better, how can I store each entry as a fraction? The matrix dimensions are 3456x5184 uint8.

  0 件のコメント

サインイン to comment.

回答 (1 件)

Chris Turnes
Chris Turnes 2016 年 3 月 15 日
Your last sentence has the answer: your data type is uint8. Dividing a uint8 by a uint8 is going to give you another integer, so you won't get any decimal places.
Your options are to convert to either double or single and do the operation, or as you said you can store each entry as a fraction. Since they are uint8, every entry of the matrix will contain the numerator, and every denominator is 98 -- so you already have all of the information.

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by