How to "Create new data" for a custom library block
Mostrar comentarios más antiguos
Hello all,
I am creating a custom library block for my project which I followed mask concept as Unit delay block. However, I got some difficulties on creating New data for my state variable. Currently, I can only create a state variable which will be stored in data dictionary by default; however, I would like to create as following Unitdelay concept. But I could not find any documents which introduced how to do these stuffs for custom library block.
Or whether are there any Parameter options available for creating this on Mask Editor? Please give me some hints here. Thank you so much!

4 comentarios
madhan ravi
el 4 de Dic. de 2023
Can you illustrate with an example of what your unit delay block does? and try to explain your use case as well.
madhan ravi
el 4 de Dic. de 2023
sorry I haven't worked with data dictionary yet, so can"t help you
Respuestas (1)
Fangjun Jiang
el 5 de Dic. de 2023
Editada: Fangjun Jiang
el 5 de Dic. de 2023
1 voto
Create a Mask for your customized library block, then when you double click the block, you will have a dialog to specify that parameter, just like the dialog you got when double click the UnitDelay block. The built-in "three dot action button" always appears on the side. Click the button and you will see the "Create variable" or "ParameterName: Create ..." option.
13 comentarios
madhan ravi
el 5 de Dic. de 2023
Fangjun, just to understand. State Name is just a like Identifier name of the block?
Fangjun Jiang
el 6 de Dic. de 2023
Editada: Fangjun Jiang
el 6 de Dic. de 2023
- State name is optional and can be left blank. The user can specify a name and a Simulink.Signal object to control the code generation variable name and properties.
- For a typical parameter, the user can specify MyParam=1 or MyParam=Simulink.Parameter(1). It will be passed to inside the mask InternalParam=MyParam. But for a State name, it does not work that way. The Simulink.Signal object name has to match the State name, but the State name can't be passed.
- Maybe the OP is having difficulty masking this "parameter" because it is a variable name. When it applies to a library block, it may require calling set_param() to change the name inside the mask dynamically. It also involves "parameterized library link".
madhan ravi
el 6 de Dic. de 2023
+1, thank you Fangjun for explaining the actual issue in lamens terms :)
Chuyen
el 8 de Dic. de 2023
Chuyen
el 8 de Dic. de 2023
Fangjun Jiang
el 8 de Dic. de 2023
Editada: Fangjun Jiang
el 8 de Dic. de 2023
Okay, so the question is really about why you see different options regarding data source (model workspace, base workspace, sldd) when you click the "three dot action" button.
The three options should always be available for new variables (two options if SLDD is not used). Try a new UnitDelay block or a new instance of your customized library block. Make sure the "enable model access to base workspace" option is checked at the model properties, "external data" tab.
For existing variables, I guess the option is limited (or constrained) to the current data source, because it wants to keep it consistent.
At your dialog showing "T3", try to change it to a new name, "T4", click apply and then click the "three dot action" button, you should see three data source options available.
Chuyen
el 11 de Dic. de 2023
Fangjun Jiang
el 11 de Dic. de 2023
It seems to me "T4" already exists in the SLDD. The variable has to be new to have multiple options.
If you need further help, please create a simple example model in R2022b to demonstrate the issue and attach the mode.
Chuyen
el 11 de Dic. de 2023
Fangjun Jiang
el 11 de Dic. de 2023
If "T4" is automatically created in SLDD by a callback function, then it explains why you always see SLDD as the only option.
The function to create a variable in base workspace is assignin('base', VarName, VarValue).
Fangjun Jiang
el 13 de Dic. de 2023
For new variables, the model workspace option should always be there.
There is API for model workspace too.
Chuyen
el 14 de Dic. de 2023
Categorías
Más información sobre Simulink en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



