Below are two examples of how to use set_param to change the properties of a block and get_param to query a block for its current properties. This example uses set_param from the MATLAB command line, but it can also be used from within an M-file or S-function. In order to find the correct paths and properties of a block, it is often useful to put the block of interest into a separate model (with nothing else in it), save the model and use the TYPE command or an editor to view the file. The code that is stored within the model (S-function) not only provides insight as to the required syntax, but also provides a list of properties that are associated with the particular block. It is important to remember to change the parameters of the block before saving and viewing the model. This is useful, because if the parameters of a block are unchanged (i.e., left as the default), they may not appear in the list of properties.
get_param('full path and name of block', 'property name')
set_param('full path and name of block','property name','property')
Everything should be in single quotes!!
- 1) Create a new model window
- 2) Drag a Gain block into the model and set the value to 2. NOTE: If the value of the gain is not changed from the default of 1, the gain value may not be listed in the M-file as a property of the Gain block.
- 3) Save the model as test1.m
- 4) At the MATLAB command line type type test1
- 5) You should see a section that reads:
>> set_param([sys,'/','Gain'],... % sys is generally defined as
% the model name at the top
% of the file
'position',[a,b,c,d]); % where a b c d are numbers
% representing the position
- So, there are two properties, Gain and Position
- 6) Use set_param to change the value of the Gain. The first argument for set_param is the full path to the block (as found above), the second argument is the property, and the third argument is the new value.
>> res=get_param('test1/Gain','Gain'); % to query the property
- 7) Click on the Gain block to see the new value of the gain.
- 1) Change the value of the Gain to 'a'.
- 2a) Mask the gain block as follows:
Block Type: New Gain
Dialog strings : Gain Value|Gain
Drawing: New Gain
Help: This is the new gain block
- 2b) Double click on the block and enter 2 in the Gain dialog box.
- 3) Re-save the file
- 4) Type "type test1" to view the file and inspect the new properties
- 5) Change the value of the gain, by changing the entry in the masked dialog box as follows:
(c) Copyright 1994 by The MathWorks, Inc.