Reputation: 228
I have a nested structure with some fields labeled as L1
, L2
etc. I try to access a substructure within the structure using the following code.
lfield = lfidcalc(le);
substruct = bmstruct.(lfield);
Since le
changes its value in every iteration, lfield
also changes its value from L1
to L9
.
However, when I try to build this code to generate a C++ executable, I get the following error.
Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression. In this context, the value of the string must be known.
Can anybody please try to help me sort out this problem?
Upvotes: 1
Views: 931
Reputation: 24127
I'm not sure exactly what's causing the error message you're seeing, but in any case MATLAB Coder does not support accessing the fields of a structure using dynamic field names.
Perhaps that is the direct cause of what you're seeing, perhaps not: but in either case you have a problem.
Upvotes: 1
Reputation: 86
Not all correct matlab code can be converted to C/C++. Especially this kind of (very handy) code. Have you put '%#eml' on the second line of your function? It indicates that you will generate code. From matlab website: " We use the %#eml directive to turn on the MATLAB M-Lint code analyzer and check the function code for errors and recommend corrections."
Upvotes: 0