How to define struct for building a mex function

조회 수: 2 (최근 30일)
Jason Lim
Jason Lim 2016년 3월 7일
답변: Walter Roberson 2016년 3월 7일
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