필터 지우기
필터 지우기

Conversion from uint8 to ascii to number

조회 수: 40 (최근 30일)
Carl-Johan Elm
Carl-Johan Elm 2012년 10월 16일
댓글: Walter Roberson 2019년 4월 12일
I am currently working with RS232 serial communication between a Trimble gps and a Speedgoat real time computer in Simulink. From the buffer in the Speedgoat i receive a uint8 array, that i want to convert to a the corresponding ascii value and then convert the new array into one double.
For example
uint8: [48 46 56 52] -> [0 . 8 4] -> 0.84
Help would be much appreciated!
  댓글 수: 2
Zhengyi Chen
Zhengyi Chen 2019년 4월 11일
You can convert uin8 data into char and use str2double() function to conver the strings in to double data type.
Walter Roberson
Walter Roberson 2019년 4월 12일
... Which is the Answer that I posted.

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2012년 10월 16일
str2double(char(TheArray))
  댓글 수: 1
Carl-Johan Elm
Carl-Johan Elm 2012년 10월 24일
Thanks but you can not use the char() or str2double() command in embedded matlab functions in simulink. =(

댓글을 달려면 로그인하십시오.


José-Luis
José-Luis 2012년 10월 24일
Somewhat convoluted, depends on whether you can use sprintf() and sscanf():
your_ascii = [48 46 56 52];
your_ascii = your_ascii - '0';
your_string = sprintf('%i',your_ascii);
% your_string = regexprep(your_string,'-','.'); %This could work also, instead of the indexing
your_string(your_string == '-') = '.';
your_val = sscanf(your_string,'%f');

Andrei Bobrov
Andrei Bobrov 2012년 10월 24일
a = uint8([50 48 46 48 48 56 52] );
i0 = a == 46;
a1 = a(~i0)-'0';
out = double(a1)*(10.^(numel(a1)-1:-1:0).')*10^-(find(i0)+1);

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by