0

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.

Adam
  • 49
  • 1
  • 1
  • 7
  • You should not work with the `try`-`catch`-block unless necessary. You could first check if the *Enable* property exists – max Jan 19 '20 at 07:57

1 Answers1

0

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

handles = [app. SelectDateDropDown, app.SelectDateLabel, ... ];
set(handles, 'Enable', false, 'Visible', false);
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120