How to define struct for building a mex function
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti

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 Commenti
Risposte (3)
Jan
il 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 Commenti
Guillaume
il 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 Commenti
Walter Roberson
il 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 Commenti
Vedere anche
Categorie
Scopri di più su Dictionaries in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!