I'm trying to display values received from serial but Matlab doesn't accept decimal numbers results. I would like to receive A=0.123 from a device, the values is multiplied by 1000 and then sent via serial to matlab.
The matlab script receives 123 but when that number is divided in order to get the original value, matlab shows 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);
Which returns
consRollKpTemp:
123
consRollKp:
0
I thought the problem was the typecast(X,type) function which
converts a numeric value in X to the data type specified by type.
and I changed it to:
consRollKpTemp = typecast([uint8(mess(typei + 1)), uint8(mess(typei + 2)),uint8(mess(typei + 3)), uint8(mess(typei + 4))], 'single');
But nothing changed. I've tried the suggestions in this question and here but they didnt' work.