Coder - Create constant for specifying array size
8 次查看(过去 30 天)
显示 更早的评论
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;
int array[arraySize];
When I write the following in the MATLAB, coder just repalces arraySize with the actual number which is 5:
arraySize=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
0 个评论
回答(1 个)
Fangjun Jiang
2019-3-15
Please refer to the document
Code Generation for Variable-Size Arrays
web(fullfile(docroot, 'simulink/ug/what-is-variable-size-data.html'))
Control Memory Allocation for Variable-Size Arrays in a MATLAB FunctionBlock
web(fullfile(docroot, 'ecoder/ug/control-memory-allocation-for-variable-size-arrays-in-a-matlab-function-block.html'))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!