필터 지우기
필터 지우기

Coder - Static size string in sprintf

조회 수: 4 (최근 30일)
amin ya
amin ya 2019년 3월 7일
편집: amin ya 2019년 3월 8일
How can I prevent MATLAB Coder to generate variable size code for a simple number insertion into a string?
for i=1:4
name=sprintf('Data%d.bin',int8(i));
stuff(name)
end
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
name=['Data',char(i),'.bin'];
Using the following also gives an error for generating code that LHS is fixed sized but RHS is varying:
coder.varsize('name',[1,14],[0,0])

채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 7일
편집: Walter Roberson 2019년 3월 7일
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
amin ya
amin ya 2019년 3월 8일
편집: amin ya 2019년 3월 8일
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.
name=['Data',int2str(i),'.bin'];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by