</pre><p></p><pre code_snippet_id="1932623" snippet_file_name="blog_20161019_2_405111" name="code" class="cpp"> int bb = 10; int cc = aa% bb; int dd = aa / bb ; cout << cc << endl << dd <<endl; cout << "cnt: " << cnt << endl;
輸出結果:
3
23
%: 取餘數
/ : 相除取整除數部分
(與MATLAB代碼的區別)
double aa = 24.4; double bb = 3.2; double cc = aa/bb; cout << "aa bb cc: " << aa <<" "<< bb <<" "<< cc <<endl; double a = 24.4; int b = 3; double c = a / b; cout << "a b c: " << a << " " << b << " " << c << endl;
MATLAB:
%計算出RGB三通道的增益%
Rgain = Ymax / Rav
Ggain = Ymax / Gav
Bgain = Ymax / Bav
Ymax = 235
Rav = 133.4989
Gav = 123.8576
Bav = 149.9403
奇了怪了, 需要用增益係數,卻輸出結果為整數 2
在命令列進行 命令計算 明明可以輸出浮點 結果
/ rdivide matlab 協助文檔解釋:
Integer Division
Divide an int16 scalar value by each element of an int16 vector.
a = int16(10);b = int16([3 4 6]);x = a./b
x = 3 3 2
MATLAB® rounds the results when dividing integer data types. 對於整數,對結果進行四捨五入處理 解決方案:
% 兩整數相除,將分母轉換為double類型 ,則輸出結果為 double型,
sumR = sum(sum(R))
Rav = double(sumR)/cnddt
輸出結果:
Rav = 133.4989