classdef app4 < matlab.apps.AppBase

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

  properties (Access = private)
    handles   % Daten für den Timer
  end
  
  methods (Access = private)
    function results = LoopFnc(app, event, string_arg)
      w = pi/2 - app.handles.seconds * pi / 30;   % Winkel zu Sekunden
      xPos = 50 * cos( w );
      yPos = 50 * sin( w );

      plot( app.UIAxes, [0 xPos], [0, yPos] )   % In Axes zeichnen  
      app.UIAxes.XLim = [ -70 70 ];
      app.UIAxes.YLim = [ -70 70 ];
      app.UIAxes.XTick = []; 
      app.UIAxes.YTick = []; 
  
      app.handles.seconds = app.handles.seconds + 1;  % Sekunden hochzählen       
      results = 0;
    end
  end

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

    % Code that executes after component creation
    function startupFcn(app)
      app.handles.seconds  = 0;
      app.handles.Timer = timer('Name','Timer', ...
                  'Period', 1, ...
                  'BusyMode', 'queue', ...
                  'StartDelay', 1,... 
                  'ExecutionMode', 'fixedrate',...
                  'TimerFcn', @app.LoopFnc );
      start( app.handles.Timer );     % Timer starten  
    end

    % Close request function: UIFigure
    function UIFigureCloseRequest(app, event)
      stop(app.handles.Timer);         % Timer stoppen 
      delete(app.handles.Timer);       % Timer löschen 
      delete(app);
    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 300 300];
      app.UIFigure.Name = 'MATLAB App';
      app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);

      % Create UIAxes
      app.UIAxes = uiaxes(app.UIFigure);
      title(app.UIAxes, 'Title')
      app.UIAxes.PlotBoxAspectRatio = [1.38341968911917 1.38341968911917 1];
      app.UIAxes.XTick = [];
      app.UIAxes.YTick = [];
      app.UIAxes.ZTick = [];
      app.UIAxes.Position = [50 50 200 200];

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

      % 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