How to convert numbers into ASCII array in Matlab Function in Simulink?
Show older comments
Hi,
to send Data via serial communication to a certain device I have to transform three numbers into an ASCII array and afterwards into a uint8 array. The numbers usually look like this:
a = 1400; %always between 1000 and 2000
b = 20;
c = -10; %b and c are angles in [°], always between -45° and 45°
The resulting Arrays have to look like this:
string = [1400,20,-10,]
out = [49 52 48 48 44 50 48 44 45 49 48 44]
The ',' are important for the receiving device to understand the signal.
For now in simulation I used following code and it worked fine:
string = [num2str(a),',',num2str(b),',',num2str(c),','];
out = uint8(string);
But for the realtime-use I have to compile the Matlab Function which means I can not use num2str or any other function like sscanf, ssprintf ect...
Do you have any idea how I could obtain the same result without using num2str?
Sincerely,
Thomas
Edit: Found a Solution. See Comment below.
Answers (0)
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!