Convert decimal to ASCII

8 ビュー (過去 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