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!

 Accepted Answer

uint8(['SO:VO ',num2str(voltage)]);

1 Comment

Mihai Ganga
Mihai Ganga on 15 Jun 2021
Edited: Mihai Ganga on 16 Jun 2021
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!

Sign in to comment.

More Answers (0)

Tags

Asked:

on 15 Jun 2021

Edited:

on 16 Jun 2021

Community Treasure Hunt

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

Start Hunting!