我想顯示從串行接收的值,但Matlab不接受小數點結果。 我想從設備接收A = 0.123,數值乘以1000,然後通過串行發送到matlab。防止MATLAB舍入數字並設置小數精度
的MATLAB程序接收123,但是當這個數字,以獲得原始值劃分,MATLAB顯示爲0。
consRollKpTemp = typecast([uint8(mess(typei + 1)), uint8(mess(typei + 2)),uint8(mess(typei + 3)), uint8(mess(typei + 4))], 'int32');
disp(consRollKpTemp);
consRollKp = consRollKpTemp/1000;
disp(consRollKp);
它返回
consRollKpTemp:
123
consRollKp:
0
我認爲這個問題是typecast(X,type)功能
將X中的數值轉換爲按類型指定的數據類型。
,我把它改成:
consRollKpTemp = typecast([uint8(mess(typei + 1)), uint8(mess(typei + 2)),uint8(mess(typei + 3)), uint8(mess(typei + 4))], 'single');
但什麼都沒有改變。我已經嘗試了this問題和here的建議,但他們沒有工作。