3
votes

Is there a way to replace variables used in a Simulink block with actual values stored in the Matlab base workspace (or model workspace) ?

e.g. In a gain block, the 'Gain' parameter is set to 'gain_A'. 'gain_A' is defined in the base workspace to '0.5'. Intended script will replace 'gain_A' in the gain block with'0.5'.

A method that I've tried is to use Simulink.findVars(modelname, 'Name', 'gain_A') which will return an object that contains a property with all the blocks that uses the variable 'gain_A'. However, it doesn't tell me which parameter it is used for (e.g. 'Gain').

Appreciate your help =)

1

1 Answers

2
votes

Not sure if this will work, but can you combine Simulink.findVars with get_param to get all the block parameters for each of the blocks identified by Simulink.findVars? As per Get a Block Parameter Value and Attributes:

block_parameters = get_param(block_path,'DialogParameters')

You could then fgifure out which parameter each variable (e.g. gain_A) is used for.