Convert decimal to ASCII

8 次查看(过去 30 天)
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