Coder - Create constant for specifying array size
5 views (last 30 days)
How can I create a constant variable in MATLAB (and its results the generated C code), so I can use it later in my code to specify the size of variables.
In C, we usually do this:
const int arraySize = 5;
When I write the following in the MATLAB, coder just repalces arraySize with the actual number which is 5:
array=zeros(1,arraySize); % zeros is just used for specifying size
(This array size may be repeated throughout the different functions and code many times, so global probably may be related to this)
I want to use static memory allocation as long as it is possible.
Related also to this question: https://www.mathworks.com/matlabcentral/answers/84419-declaring-const-variable-in-generated-code
Fangjun Jiang on 15 Mar 2019
Please refer to the document
Code Generation for Variable-Size Arrays
Control Memory Allocation for Variable-Size Arrays in a MATLAB FunctionBlock