4

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

ken
  • 3,897
  • 3
  • 22
  • 28

1 Answers1

3

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.

am304
  • 13,758
  • 2
  • 22
  • 40
  • Thanks! I think this would work. I'm just a little worried about the performance for large models as I will need to loop through each dialog parameter to find for the corresponding variable. Do you know if there is a way to manually resolve symbols as is done during compilation? [link](http://www.mathworks.com.au/help/simulink/ug/resolving-symbols.html) – ken Jul 20 '13 at 03:40
  • Sorry, no. I have to confess I didn't even know about resolving symbols during compilation. *hangs head in shame* – am304 Jul 20 '13 at 13:01
  • No worries! Thanks for your suggestion. I will give it a go and see how it performs. – ken Jul 21 '13 at 02:29