Is there a way to ask MATLAB Coder 2.3 (R2012b) to perform the assignment of a persistent variable within the FUNCTIONNAME_initialize function?

조회 수: 1 (최근 30일)
I have a MATLAB function that contains code of the form :
persistent myVariable;
if(isempty(myVariable))
myVariable = rand(1,10);
end
the generated C/C++ code does not assign the initial value of 'myVariable' within the FUNCTIONNAME_initialize function. Instead it assigns it within the FUNCTIONNAME function within a c-style if isempty section.
Is it possible to tell coder to perform persistent assignments within FUNCTIONNAME_initialize?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2013년 1월 28일
In general MATLAB coder will try to put the persistent initialization within the FUNCTIONNAME_initialize function. For example for the following MATLAB code:
if(isempty(myVariable))
myVariable = 5;
end
'myVariable'' is initialized to 5.0 within the FUNCTIONNAME_initialize function.
In this case the variable initialization also consists of a function call to RAND. This is why it is not in the FUNCTIONNAME_initialize . The FUNCTIONAME_initialize function is not intended to contain the implementation of the MATLAB code (in this case the variable initialization is tied to the implementation of the RAND call).

추가 답변 (0개)

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2012b

Community Treasure Hunt

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

Start Hunting!

Translated by