I understand that you want to set or change the "Variable name" parameter of this "To Workspace" block dynamically, i.e., from outside the subsystem, by using a mask parameter on the subsystem itself.
In Simulink, when you create a mask for a subsystem or block, the parameters defined in the mask are local to the mask's workspace. These mask parameters are not automatically propagated to the parameters of the blocks contained within the masked subsystem. This design allows for encapsulation and modularity but requires explicit actions to link mask parameters to internal block parameters.
You can refer to the following documentation link for more information regarding masking:
This means that to update a parameter like "VariableName" in a "To Workspace" block based on a mask parameter, you should use the “set_param” function in the mask callback code.
You can follow the below steps to update “VariableName” in “To Workspace” block:
- Add a “Edit” parameter in the mask editor.
- In the Property Editor -> Dialog -> Callback add the logic for changing the “VariableName” in “To Workspace” block.
For example, consider the below model under mask. Here, the “VariableName” is “simout”.
The below callback code can be used given that “workspaceName” is the properties name.
Keep the “Evaluate” option in the property editor unchecked else Simulink will try to evaluate the name entered which will throw error.
The dialog box prompting to input the variable name:
Upon simulating, “myVar” appears in the base workspace instead of the “simout” variable.
Another easier way to achieve this is by using Parameter promotion which avoids writing callbacks. Please refer to the following documentation for more details:
This allows option on the Mask Editor for one-to-one correspondence between the block parameter and the mask parameter.
I hope this resolves your query.