How to define struct for building a mex function

1 次查看(过去 30 天)
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.

回答(3 个)

Jan
Jan 2016-3-7
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', {});

Guillaume
Guillaume 2016-3-7
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));

Walter Roberson
Walter Roberson 2016-3-7
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.)

类别

Help CenterFile Exchange 中查找有关 Dictionaries 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by