I got an 'Could not find initial value for global variable' error message when I build a MATLAB function with MATLAB coder

10 ビュー (過去 30 日間)
Hello,
I'm trying to get a auto-generated code for a MATLAB function. Many things happened and I coded again to fit it to MATLAB coder. But I'm not able to find the solution to the error message.
'Could not find initial value for global variable xxx'
I explicitly declared global variables in my MATLAB function code. So I think I don't need to assign values to them.
What is the cause of this erroe message? Do you have any solution to avoid it?

採用された回答

Sainath Varikuti
Sainath Varikuti 2015 年 7 月 22 日
編集済み: Sainath Varikuti 2015 年 7 月 22 日
Hello JangHo Cho,
While generating code for global data the workflow is
1) Declare the variables as global in your code.
2) Define and initialize the global data before using it.
3) Compile the code
for example, following function uses global variables:
function y = use_globals()
%#codegen
% Turn off inlining to make
% generated code easier to read
coder.inline('never');
% Declare AR and B as global variables
global AR;
global B;
AR(1) = B(1);
y = AR * 2;
Step 1: In order to generate code.
% Define and initialize AR and B in MATLAB workspace
global AR B
AR = 1, B = 2;
Step 2: Generate code
codegen use_globals
Regards,
Sainath
  2 件のコメント
Ryan Livingston
Ryan Livingston 2015 年 7 月 23 日
Note that an entry-point function will never be inlined. So using coder.inline('never') in it has no effect.
JangHo Cho
JangHo Cho 2015 年 7 月 24 日
Thank you Sainath Varikuti for your clarification. I should declare the global variables in the command window before I start code-generation. Thank you Ryan Livingston for your comment, though I don't know about the options you said. :)

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by