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.
I want to have an array that its size is not hardcoded via number all over the code. I want to specify the size at the beginning of the code like how we do in C code using one of the followings:
const int arraySize=5
#define arraysize 5
Later: int array[arraySize];
When I write the following in MATLAB, Coder just replaces arraySize with the actual number which is 5:
arraySize=int8(5);
array=zeros(1,arraySize); % zeros is just used for specifying size
Generated code:
void coder(double A[5])
{
memset(&A[0], 0, sizeof(double) << 16);
}
I tried using the following but it does not allow me to use arraySize in MATLAB calculations:
arraySize=coder.opaque('const int16','5');
A=zeros(1,arraySize);
This may be related to constant folding which I can not disable!
This array size may be repeated throughout the different functions and code many times, so global probably may be related to this