Timo Schneider
Timo Schneider

Reputation: 19

Edit displayed text in a simulink mask when the block gets initialized

I have a cell array of strings. Now i want to display these strings as text in the mask of a subsystem, not on the block of the subsystem itself. It is also no problem, if you have to hit the aplay button between the giving the strings and when they will be displayed. Perhabs a callback function could make this step in a final version.

The cell array will be different from subsystem to subsystem.

I made a picture. It is on my dropbox. Picture for a better understanding

In the actual mask, the cell array will be generated from an Object of a custom class. Then you first give the subsystem this object whith the cell array. Then you initialize the the block and then the strings of the cell array should be desplayed in the mask. This is because these strings are options in the subsystem. Then you can type the options you like into an edit fiel in the mask. But the second part isn't a problem. My problem is to display the text in the cell array in the mask.

Thanks for your help.

Upvotes: 0

Views: 4332

Answers (1)

Phil Goddard
Phil Goddard

Reputation: 10772

Here's an example that just uses a single string, but it should be relatively easy to modify to work will a cell array of strings.

enter image description here

Consider a simple model (top left of the image) that contains a masked subsystem. The mask contains one parameter and one Text Control (as shown in the mask editor and the mask itself).

Of particular significance is

  1. The Evaluate and Tunable attribute of the Parameter have been de-selected. (You may want these to be selected, and the rest of the example should still work.)
  2. The Name property of the Text Control has been specified as 'TextControl' (this tag will be used later).

On the Initialization Pane of the Mask Editor, enter the following code:

% Get the mask object
mo = get_param(gcb,'MaskObject');
% Get the text object
tc = mo.getDialogControl('TextControl');
% Change the string
tc.Prompt = mo.Parameters(1).Value;

Again, note that the above only works if there is one parameter. If you have more than one control on the mask then you'll need to modify the above to get the correct string (or cell array of strings) from the correct parameter.

You also need to execute the following at the MATLAB command line (after selecting the subsystem block by left clicking on it)

set_param(gcb,'MaskSelfModifiable','on');

which tells Simulink that the mask is allowed to change the block.

With all of the above, if you enter a string into the edit box on the mask, then press Apply (or have initialization occur at any other time), then the entered string will appear in the text area of the mask.

Upvotes: 3

Related Questions