Convert decimal to ASCII

조회 수: 9 (최근 30일)
Mihai Ganga
Mihai Ganga 2021년 6월 15일
편집: Mihai Ganga 2021년 6월 16일
Hello everyone,
I'm trying to convert some small decimal numbers (e.g. 0.250, 2.500) to ASCII values so I can send them to some power supply via serial. When using a simple MATLAB script it worked pretty well using "sprintf" (e.g. uint8(sprintf('SO:VO %.4f\n', voltage));) but when trying to use Simulink Realtime I am not able to use sprintf anymore.
I would like to write a small function to do this but don't know where to start.
Any advice is much appreciated!

채택된 답변

David Hill
David Hill 2021년 6월 15일
uint8(['SO:VO ',num2str(voltage)]);
  댓글 수: 1
Mihai Ganga
Mihai Ganga 2021년 6월 15일
편집: Mihai Ganga 2021년 6월 16일
Hi David, thanks for your answer but unfortunately when migrating from script/simulation to realtime and I have tot compile the model I am also not allowed to use num2str method either. I think that basically I have to do a function that outputs the same as num2str or sprintf.
Later edit: My bad. I got the chance to test the method with num2str and seems to work. Thanks!

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by