I am trying to add a switch in app designer using this code:
function SwitchValueChanged(app, event)
value = app.Switch.Value;
if (value == 'Off')
app.SaveOIButton.Enable = 'Off';
app.OpenOIButton.Enable = 'Off';
end
if (value == 'On')
app.SaveOIButton.Enable = 'On';
app.OpenOIButton.Enable = 'On';
end
end
but I get this error:
Arrays have incompatible sizes for this operation.
Error in Mie/SwitchValueChanged (line 82)
if (value == 'Off')
Related documentation
Error while evaluating Switch PrivateValueChangedFcn.
Any idea why?
Try (I did not run it):
function SwitchValueChanged(app, event)
switch app.Switch.Value
case 'Off'
app.saveOIButton.Enable = 'off';
app.openOIButton.Enable = 'off';
case 'On'
app.saveOIButton.Enable = 'on';
app.openOIButton.Enable = 'on';
end
end
I used the switch to evaluates an expression and chooses to execute one of several groups of statements. Each choice is a case. The switch block tests each case until one of the case expressions is true (https://www.mathworks.com/help/matlab/ref/switch.html)