classdef app3 < matlab.apps.AppBase

  % Properties that correspond to app components
  properties (Access = public)
    UIFigure       matlab.ui.Figure
    DropDown       matlab.ui.control.DropDown
    DropDownLabel  matlab.ui.control.Label
    UIAxes         matlab.ui.control.UIAxes
  end

  properties (Access = private)
    handles % Description
  end
  

  % Callbacks that handle component events
  methods (Access = private)

    % Code that executes after component creation
    function startupFcn(app)
      [X,Y] = meshgrid(-8:.5:8); 
      R = sqrt(X.^2 + Y.^2) + eps;
      app.handles.Z = sin(R)./R;
      surf( app.UIAxes, app.handles.Z );     
    end

    % Value changed function: DropDown
    function DropDownValueChanged(app, event)
      value = app.DropDown.Value;
      if( strcmp( value, 'surf' ) )
        surf( app.UIAxes, app.handles.Z );      
      else
        mesh( app.UIAxes, app.handles.Z );      
      end
    end
  end

  % Component initialization
  methods (Access = private)

    % Create UIFigure and components
    function createComponents(app)

      % Create UIFigure and hide until all components are created
      app.UIFigure = uifigure('Visible', 'off');
      app.UIFigure.Position = [100 100 435 377];
      app.UIFigure.Name = 'MATLAB App';

      % Create UIAxes
      app.UIAxes = uiaxes(app.UIFigure);
      title(app.UIAxes, 'Title')
      xlabel(app.UIAxes, 'X')
      ylabel(app.UIAxes, 'Y')
      zlabel(app.UIAxes, 'Z')
      app.UIAxes.XTick = [];
      app.UIAxes.YTick = [];
      app.UIAxes.ZTick = [];
      app.UIAxes.Position = [69 160 300 185];

      % Create DropDownLabel
      app.DropDownLabel = uilabel(app.UIFigure);
      app.DropDownLabel.HorizontalAlignment = 'right';
      app.DropDownLabel.Position = [129 79 65 22];
      app.DropDownLabel.Text = 'Drop Down';

      % Create DropDown
      app.DropDown = uidropdown(app.UIFigure);
      app.DropDown.Items = {'surf', 'mesh'};
      app.DropDown.ValueChangedFcn = createCallbackFcn(app, @DropDownValueChanged, true);
      app.DropDown.Position = [209 79 100 22];
      app.DropDown.Value = 'surf';

      % Show the figure after all components are created
      app.UIFigure.Visible = 'on';
    end
  end

  % App creation and deletion
  methods (Access = public)

    % Construct app
    function app = app3

      % Create UIFigure and components
      createComponents(app)

      % Register the app with App Designer
      registerApp(app, app.UIFigure)

      % Execute the startup function
      runStartupFcn(app, @startupFcn)

      if nargout == 0
        clear app
      end
    end

    % Code that executes before app deletion
    function delete(app)

      % Delete UIFigure when app is deleted
      delete(app.UIFigure)
    end
  end
end