1

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?

alirazi
  • 159
  • 8

1 Answers1

2

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)

AsiJapan
  • 313
  • 1
  • 10
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 15 '22 at 10:28