classdef app_3_3_1 < matlab.apps.AppBase

  % Properties that correspond to app components
  properties (Access = public)
    UIFigure             matlab.ui.Figure
    maxEditField         matlab.ui.control.NumericEditField
    maxEditFieldLabel    matlab.ui.control.Label
    minEditField         matlab.ui.control.NumericEditField
    minEditFieldLabel    matlab.ui.control.Label
    GrafikDropDown       matlab.ui.control.DropDown
    GrafikDropDownLabel  matlab.ui.control.Label
    UIAxes               matlab.ui.control.UIAxes
  end

  
  properties (Access = private)
    minVal = 0;     % untere Grenze
    maxVal = 2*pi;  % obere Grenze
  end
  

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

    % Code that executes after component creation
    function startupFcn(app)
      app.minEditField.Value = app.minVal;
      app.maxEditField.Value = app.maxVal;
      x = linspace( app.minVal, app.maxVal, 50 );
      y = sin(x);
      plot( app.UIAxes, x, y );
    end

    % Value changed function: GrafikDropDown
    function GrafikDropDownValueChanged(app, event)
      value = app.GrafikDropDown.Value;
      x = linspace( app.minVal, app.maxVal, 50 );
      
      if( value == "sin" )
        y = sin(x);
      elseif( value == "cos" )
        y = cos(x);
      elseif( value == "exp" )
        y = exp(x);
      else
        y = sin(x);
        beep();
      end

      plot( app.UIAxes, x, y );
    end

    % Value changed function: minEditField
    function minEditFieldValueChanged(app, event)
      value = app.minEditField.Value;
      if( value < app.maxVal )
        app.minVal = value;
        GrafikDropDownValueChanged(app, event);
      else
        app.minEditField.Value = app.minVal;
        beep();
      end
    end

    % Value changed function: maxEditField
    function maxEditFieldValueChanged(app, event)
      value = app.maxEditField.Value;
      if( value > app.minVal )
        app.maxVal = value;
        GrafikDropDownValueChanged(app, event);
      else
        app.maxEditField.Value = app.maxVal;
        beep();
      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 368 323];
      app.UIFigure.Name = 'MATLAB App';

      % Create UIAxes
      app.UIAxes = uiaxes(app.UIFigure);
      title(app.UIAxes, 'Funktionen')
      xlabel(app.UIAxes, 'X')
      ylabel(app.UIAxes, 'Y')
      zlabel(app.UIAxes, 'Z')
      app.UIAxes.Position = [11 75 351 228];

      % Create GrafikDropDownLabel
      app.GrafikDropDownLabel = uilabel(app.UIFigure);
      app.GrafikDropDownLabel.HorizontalAlignment = 'right';
      app.GrafikDropDownLabel.Position = [31 43 37 22];
      app.GrafikDropDownLabel.Text = 'Grafik';

      % Create GrafikDropDown
      app.GrafikDropDown = uidropdown(app.UIFigure);
      app.GrafikDropDown.Items = {'sin', 'cos', 'exp'};
      app.GrafikDropDown.ValueChangedFcn = createCallbackFcn(app, @GrafikDropDownValueChanged, true);
      app.GrafikDropDown.Position = [83 43 100 22];
      app.GrafikDropDown.Value = 'sin';

      % Create minEditFieldLabel
      app.minEditFieldLabel = uilabel(app.UIFigure);
      app.minEditFieldLabel.HorizontalAlignment = 'right';
      app.minEditFieldLabel.Position = [213 43 25 22];
      app.minEditFieldLabel.Text = 'min';

      % Create minEditField
      app.minEditField = uieditfield(app.UIFigure, 'numeric');
      app.minEditField.ValueChangedFcn = createCallbackFcn(app, @minEditFieldValueChanged, true);
      app.minEditField.Position = [253 43 56 22];

      % Create maxEditFieldLabel
      app.maxEditFieldLabel = uilabel(app.UIFigure);
      app.maxEditFieldLabel.HorizontalAlignment = 'right';
      app.maxEditFieldLabel.Position = [211 14 28 22];
      app.maxEditFieldLabel.Text = 'max';

      % Create maxEditField
      app.maxEditField = uieditfield(app.UIFigure, 'numeric');
      app.maxEditField.ValueChangedFcn = createCallbackFcn(app, @maxEditFieldValueChanged, true);
      app.maxEditField.Position = [254 14 56 22];

      % 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 = app_3_3_1

      % 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