How to define struct for building a mex function
1 view (last 30 days)
Show older comments

In the picture 'hashtable' is structure with two fields 'L'(X*2 double) and 'N' (X*4 double) .
And X is not a fixed value.
Please let me know How should I define 'hashtable'. I Need help.
0 Comments
Answers (3)
Jan
on 7 Mar 2016
The error message tells you, that the variable "hashtable" does not exist before this call. What is "tempA"?
What about initialising?
hashtable = struct('L', {}, 'N', {});
0 Comments
Guillaume
on 7 Mar 2016
Initialise the structure with empty fields of the correct type. In your case, since the type of the fields is double, simply initialising with zeros should work:
hashtable = struct('L', zeros(0, 2), 'N', zeros(0, 4));
0 Comments
Walter Roberson
on 7 Mar 2016
The error message is being generated during Simulink code generation, which has special rules about initialization. You need to determine the maximum value that can be used for tempA and initialize a struct that size.
hashtable(MaxTempA) = struct('L', zeros(0, 2), 'N', zeros(0, 4));
I have not read enough about the restrictions on code generation to know if you need to initialize all of the struct entries right at the beginning.
In Simulink code generation, using an initial dimension of 0 has special meaning. Please read http://www.mathworks.com/help/fixedpoint/ug/defining-variable-size-data-for-code-generation.html (and you might find you need to adjust the syntax I show above.)
0 Comments
See Also
Categories
Find more on Dictionaries in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!