Insert char into array in embedded function
6 views (last 30 days)
Show older comments
Hello, I am trying to send array of data to arduino through Serial Send, however due to not knowing how large records will be ( each can range from 80 to 1000) I want to separate each data with coma in order to read them in arduino ( so I can go byte by byte and whenever there is a coma I will know that that record ends) . I tried inserting them in embedded function and casting result into uint8 but I am getting error about unknown output sizes. Is there any way to do it (or maybe better way to read array od data in arduino)?
function y = fcn(a,b,c,d,e)
q=[a,',',b,',',c,',',d,',',e,'|'];
y = typecast(q,uint8);
Thanks, Tom
2 Comments
Walter Roberson
on 14 Apr 2018
As this is an embedded function, then your a b c d e must all be numeric. Are you sure you want to do the equivalent of char() of each of them as you build q? Or do you want to format them?
If I recall correctly, support for sprintf() was not added to Coder until R2018a; as far as I could tell in previous versions the work-around was to use coder.ceval() to invoke sprintf()
Accepted Answer
Walter Roberson
on 15 Apr 2018
You would need to use coder.varsize() to declare the output string probably, and you would sprintf into it. If you are using before r2018a you might need to coder.ceval() to use sprintf.
You cannot just use char() on your values because you need to emit the printable equivalent of your values like '400' not char(400)
More Answers (0)
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!