Convert decimal to ASCII

8 visualizaciones (últimos 30 días)
Mihai Ganga
Mihai Ganga el 15 de Jun. de 2021
Editada: Mihai Ganga el 16 de Jun. de 2021
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!

Respuesta aceptada

David Hill
David Hill el 15 de Jun. de 2021
uint8(['SO:VO ',num2str(voltage)]);
  1 comentario
Mihai Ganga
Mihai Ganga el 15 de Jun. de 2021
Editada: Mihai Ganga el 16 de Jun. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by