The ability to dynamically change the icon of a masked subsystem from the MATLAB Command Prompt is available in Simulink 7.4 (R2009b).
In order to this, we need to define a callback function in the 'Initialization' pane of the mask editor window. Please execute the following steps for a clearer understanding of the attached example.
1. Download the attached files i.e. 'drawbattery.m', 'new_battery.bmp' and 'test_battery.mdl'.Ensure that you save all these files in the same directory.
2. Open the mask editor of the 'Subsystem2' block in the model. In the 'Parameters' pane of the mask editor, note that parameters 'a' and 'b' are defined to get the values from the MATLAB workspace. But they are not shown in the mask dialog box since the 'Show Parameter' option is unchecked for both of them. This option is available under 'Generic Options' in the 'Parameters' pane.
3. The 'Initialization' pane calls an external MATLAB function (drawbattery.m) to modify the icon of the masked subsystem. In this MATLAB function, we read the row and columns parameters entered by the user and the sample image that we need to replicate based on the inputs provided. Using the REPMAT function, we replicate the matrix of the image as needed, create a new image from this new matrix and then save this image before it is read by the IMREAD function in the 'Icon & Ports' pane of the mask editor window.
4. Now, if you update the model or simulate it, you will notice that the icon of the mask block will update based on the row and column inputs that you entered at the MATLAB Command Prompt.
Best Answer