Reputation: 71
I'm working on a MATLAB Coder project where I want to load some constant values. After trying many possibilities, all unsuccessfully, I came up with the "coder.load" directive that loads variables from MAT files and assumes them as compile time constants in generated C-code.
This is the error that I get:
Found unsupported class for variable using function 'coder.load'. Mixed field types in structure arrays are not supported. Type at 'ind_x.params(1).name' differed from type at 'ind_x.params(2).name'.
But the problem is that the "name" field of the "params" structure array has the same type for each array element. Indeed, trying it out on the command window gives me the same type:
>> class(ind_x.params(1).name)
ans =
char
>> class(ind_x.params(2).name)
ans =
char
There are other fields of the structure array that are of type "double", and one of type "bool", but the type doesen't change inside different array elements of the same field, that's why I don't understand the error.
Upvotes: 3
Views: 1501
Reputation: 71
Ok I think I found the answer to my question. The problem indeed was the character string length. If one of the fields of the structure array is of type "char", then it has to be of the same lenght for every array element. That is, if you define
ind_x.params(1).name = 'john';
ind_x.params(2).name = 'harry';
It will throw an error if you try to load that structure with coder.load()
because length(ind_x.params(1).name)
is different from length(ind_x.params(2).name)
. A workaround could be to define a maximum length and add trailing spaces to the string.
This limitation may come from the constants definitions in C, but what I found messy is the misleading error message. Thanks anyway for the help!
EDIT : I realized that the above restriction for constant structure arrays is valid not only for type "char", but for every type! You can't have a field whose length is varying within different array elements.
Upvotes: 3