lineinthesand
lineinthesand

Reputation: 247

How can I modify a matlab/simulink mask depending of the state of the mask?

I'm trying to set the Enabled state of a check box in a matlab/simulink mask (GUI) depending on the state of another check box. In other words: if check box A is checked, check box B shall be disabled (greyed). I tried to use a callback function on check box A:

box_A = get_param(gcb, 'checkBoxA');
m = Simulink.Mask.get(gcb);
box_B = m.getParameter('checkBoxB');

if strcmp(box_A, 'on')
    box_B.set('Enabled', 'off');
end

But when I open the mask, I get an error:

-->Error evaluating 'MaskCallback' callback of TEST block (mask) 'test_simulink /Test test'. -->Invalid inputs specified for method 'set' -->Attempt to modify mask parameter name of block 'test_simulink/Test test' in its MaskCallbacks. Changing mask parameter name as part of MaskCallbacks is not allowed.

How can I accomplish my initial goal?

Upvotes: 0

Views: 5503

Answers (1)

lineinthesand
lineinthesand

Reputation: 247

I finally found the solution; the trick is not to use the set function, but to assign to the Enabled property:

box_A = get_param(gcb, 'checkBoxA');
m = Simulink.Mask.get(gcb);
box_B = m.getParameter('checkBoxB');

if strcmp(box_A, 'on')
    box_B.Enabled = 'off';
else
    box_B.Enabled = 'on';
end

Upvotes: 3

Related Questions