How to generate lookup table data into a custom structure?

How to generate lookup table data into a custom structure?
When generate code, the input data of several lookup tables(or my own S-Functions) are all
generated into modelname_data.c / modelname_ConstP{} Struct. But i want to put each blocks'
data in different struct. Besides, i want to put different struct into different memory
section.
e.g. I create my own S-function "mylookup1D", which has XData and YData. Then i put two
mylookup1D in a model "test" and input XData and Ydata value. After code generation,
mylookup1D_XData, mylookup1D_YData, mylookup1D1_XData, mylookup1D1_YData are all generated into
struct test_ConstP{}. But i want to put mylookup1D_XData, mylookup1D_YData in one struct and
mylookup1D1_XData, mylookup1D1_YData in another.
How to do this???
Thanks a lot!

Answers (1)

Instead of defoning look-up table array directly in the Look-up table block itself, define them as Simulink.Parameter object in base workspace. Use these parameters in look0up table block.
Now define the storage class of parameter as Custom -> struct. For example your parameters are mylookup1D_XData & mylookup1D_YData. Declare these parametrs in base workspace as
mylookup1D_XData = Simulink.Signal;
mylookup1D_XData.RTWInfo.StorageClass = 'Custom';
mylookup1D_XData.RTWInfo.CustomStorageClass = 'Struct';
mylookup1D_XData.RTWInfo.CustomAttributes.StructName = MyStruct1;
mylookup1D_YData = Simulink.Signal;
mylookup1D_YData.RTWInfo.StorageClass = 'Custom';
mylookup1D_YData.RTWInfo.CustomStorageClass = 'Struct';
mylookup1D_YData.RTWInfo.CustomAttributes.StructName = MyStruct1;
In this way mylookup1D_XData & mylookup1D_YData will be generated in MyStruct1. Similarly you can create another struct for other 2 parametrs.
[EDITED][20-March-2012 8:28 pm]
TLC files for look-up table (look_up.tlc, lookup2d.tlc, lookup_nd.tlc) are available in
MATLAB_ROOT\R2010b\rtw\c\tlc\blocks

3 Comments

The point is that i want to define look-up table array directly in the Look-up table. Define input data as Simulink.Parameter in workspace is a bit of complicated in application --- you have to name and configure every parameter. I have tried created custom package "mypkg" and custom storage class "myStruct", and it did work.
But for optimization, i wonder if it possible to input look-up table array directly in the Look-up table block itself and generate table code in different "struct"s ?
ps: Maybe i need to study more about how matlab deal with data storage when generating code. Besides, do you think modifying/creating related TLC files would be a solution ? But i don't know which file should i modify...
Thanks anyway!!! Looking forward to your reply~~~
Modifying tlc file is always an option for customizing the code generation, but modifying tlc of inbuilt simulink block is strongly not recommended. If you are modifying tlc make sure to back up original files.
---------
TLC files for look-up table (look_up.tlc, lookup2d.tlc, lookup_nd.tlc) are available in
MATLAB_ROOT\R2010b\rtw\c\tlc\blocks
---------
Another option is, you can write your own s-function for look-up & implement it's inlining tlc as per your requirement.
As you pointed out, i write my own s-function "mylookup1D" and its inlining TLC. In my opinion, this block TLC can only control the output code in model_initialize() function and model_step() function in model.c file. It can not control how data are orgnized or constructed in generated code. So if i have to modify/create TLC file, maybe i should modify/create TLC file which can control how data are declared and constructed. But i don't know how to do that ???

Sign in to comment.

Products

Asked:

on 20 Mar 2012

Community Treasure Hunt

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

Start Hunting!