Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Generating code for a subsystem accepting structure parameter

Asked by Sinan Pakkan on 10 Jul 2012

Hi,

I'm trying to generate code (using S-function target TLC) for a subsystem with several components accepting parameters, which are fields of a Matlab variable of type structure. I would like the structure parameter fields be tunable in the generated code. - Non-tunable rate transition, ZOH, etc. blocks' parameters are not fields of this structure. - Tunable parameter syntax restrictions in Constant source blocks (such as avoiding [,] and structure referencing) are followed. - A Simulink.Parameter object with value struct is defined in the Base Workspace. - When building the subsystem, this parameter is checked to be "tunable".

However, During the build process Matlab returns a warning in the command window telling me that the the parameter X, which is my structure parameter, is not a built-in type therefore cannot be tunable. Apart from this issue the build process turns out to be OK.

Any ideas what may have gone wrong?

Thanks in advance, Sinan Pakkan

4 Comments

Kaustubha Govind on 10 Jul 2012

Also, does the structure have all numeric fields, or are any of the fields non-numeric? Simulink does not support non-numeric structures as tunable parameters.

Sinan Pakkan on 11 Jul 2012

I've seen the comment of Kaustubha Govind in Matlab help as well. Therefore, I made sure that there exists no non-numeric fields in the structure.

In fact, the Simulink.Parameter object definition is what bugs me. The procedure I followed is: From model explorer interface, I "add Simulink parameter" to the Base workspace and in the value field I select the structure variable that is available in the Matlab Base workspace at the moment. When this variable is selected "<1x1 struct>" expression is displayed in the Value field of the "add parameter dialog" while the DataType field shows "struct" automatically.

About giving "more detail regarding how I have defined the structure", I can tell that it's a multi-level (a few fields of the structure are themselves structures) 1x1 variable of type "struct" with all numeric entries not even including NaN values. But I'm not sure if this is the question you were asking(?)

Babak on 1 Aug 2012

- Not all block's parameters are tunable.. for example sampling time cannot be tunable - you also need to create a Simulink.Bus object and set the DataType of the Simulink.Parameter object as the Bus object you just created... this way in the generated code, the structure's fields appear correctly. -MATLAB spits warning for some of the Tunable parameters still if they are places inside a vector like [a,b] or are in the form of a power like a.^3.

Sinan Pakkan

1 Answer

Answer by TAB on 12 Jul 2012
Edited by TAB on 12 Jul 2012

I think problem is due to you are using multi-level (a few fields of the structure are themselves structures) structure.

See the structure parameter limitations here.

Try using a structure which contains numerical values in all the fields.

MyStruct.Value1 = 100;
MyStruct.Value2 = 200;
MyStruct.Value3 = 500;
MyParam = Simulink.Parameter;
MyParam.Value = MyStruct;

I can't test this feature because I am far behind in the race and using R2007a. :-(

2 Comments

Sinan Pakkan on 12 Jul 2012

I just realized this limitation "You cannot define individual substructures or fields within a structure parameter as tunable." and tried generating code with a very simple model (a subsystem including a single gain, which accepts a structure field dereferenced as s.f1).

Result is the same...-> "parameter is not a built-in type, therefore cannot be made tunable".

BTW I'm not quite sure if I get the concept "Associate a Simulink.Parameter object with the structure parameter..." which is written on the same page you refer to. What I did was: Create a Simulink.Parameter object; Select the structure parameter as the "Value" field of this object; replace, in the model, the structure parameter with the Simulink.Parameter object created; Generate code...

TAB on 12 Jul 2012

Does model build successfully after your changes ?

TAB

Contact us