Search code examples
matlabsimulinkmatlab-app-designer

Is there any proper way to simplify these lines of code?


So basically I have in my MATLAB code a lot of lines like these:

% Hides SelectDateDropDown object.
app.SelectDateDropDown.Enable = false;
app.SelectDateDropDown.Visible = false;
app.SelectDateLabel.Enable = false;
app.SelectDateLabel.Visible = false;

% Hides Previous object.
app.PreviousButton.Enable = false;
app.PreviousButton.Visible = false;

% Hides Next object.
app.NextButton.Enable = false;
app.NextButton.Visible = false;

% Hides UnitsDropDown object.
app.SelectUnitsDropDown.Enable = false;
app.SelectUnitsDropDown.Visible = false;
app.SelectUnitsLabel.Enable = false;
app.SelectUnitsLabel.Visible = false;

...then similar lines to show these object etc... I am trying to figure out what could be the best "line-saving" method but unsuccessfully. These objects are varying sometimes, sometimes they don't have Enable property, but it can be solved with try-catch block.

Have you any ideas?

Thanks for any suggestions.


Solution

  • You can use the set function with an array of handles:

    handles = [app. SelectDateDropDown, app.SelectDateLabel, ... ];
    set(handles, 'Enable', false, 'Visible', false);