MATLAB: How to store user data into a Simulink block

blockdatalookupmatrixmodelparametersavesimulinkstoretableuserdatauserdatapersistent

How do I store user data into a Simulink block?
For example, I have a large data set I want to associate with a Simulink block such as the n-D Look-Up. When I use the SET_PARAM function to set the data set, part of the data is truncated when I re-open the model later.

Best Answer

There is a size constraint on how many characters can fit into a string block parameter. To work around this issue, try to use the USERDATA parameter into the MDL file as a MAT-file.
For example to associate table_values into the n-D Lookup Table block, try the following:
1. Click the n-D Lookup Table block and type the following at the MATLAB command prompt:
 
set_param(gcb,'UserDataPersistent','on')
set_param(gcb,'UserData', table_values)
where table_values is the actual table values of double data-type.
2. Double click the n-D Lookup Table and enter table_values for the "Table data" parameter.
3. Right click the n-D Lookup Table block and select "Block properties..."
4. Click the "Callbacks" tab and place the following code in the "LoadFcn" callback function:
 
table_values = get_param(gcb,'UserData')