Coder - Static size string in sprintf

1 view (last 30 days)
How can I prevent MATLAB Coder to generate variable size code for a simple number insertion into a string?
for i=1:4
In the generated C code it uses a lot of functions like emxutil to determine the size of the generated string for sprtintf.
I just want to say that i is only one digit. How can I do that?!
The followings also do not work
Using the following also gives an error for generating code that LHS is fixed sized but RHS is varying:

Accepted Answer

Walter Roberson
Walter Roberson on 7 Mar 2019
Edited: Walter Roberson on 7 Mar 2019
If you know that it is a single digit then do not use that technique. Instead you can use
name = ['Data', char(i+'0'), '.bin']
Or if you really need to
name = 'DataX.bin';
name(5) = char(i+48);
  1 Comment
amin ya
amin ya on 8 Mar 2019
Edited: amin ya on 8 Mar 2019
Thank you. Your code works very well with one digit.
I just tested the following again. It works good also and can be used for more digits, and it does not use var size stuff.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!