MATLAB: How to change the annotations of a block in Simulink to reflect the value of the parameter variable from the workspace

annotateblockdrawgraphicsmasksimulinkvalue

I would like to be able to have an annotation for a block which displays the name of the block and the value of the parameter which is defined in the base workspace.

Best Answer

You would need to edit the 'AttributesFormatString' property of the block to reflect the parameter value. One way to do this would be to place the following code in the 'InitFcn' or 'LoadFcn' of a block. An example to display the value of a Gain block on it is shown.
set_param(gcb,'AttributesFormatString',['= ' num2str(evalin('base',get_param(gcb,'Gain')))])
*For versions earlier than R2006a please use "eval(get_param(gcb,'Gain'))" instead of "evalin".