How to define struct for building a mex function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens

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 commentaires
Réponses (3)
Jan
le 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 commentaires
Guillaume
le 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 commentaires
Walter Roberson
le 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 commentaires
Voir également
Catégories
En savoir plus sur Dictionaries dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!