ken
ken

Reputation: 4077

Script to replace variables used in simulink blocks with a value

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 =)

Upvotes: 4

Views: 4696

Answers (1)

am304
am304

Reputation: 13876

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 figure out which parameter each variable (e.g. gain_A) is used for.

Upvotes: 3

Related Questions