classdef App_2023_09_15 < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                matlab.ui.Figure
        StartButton             matlab.ui.control.Button
        NextButton              matlab.ui.control.Button
        BeoordelingButtonGroup  matlab.ui.container.ButtonGroup
        EpilepticButton         matlab.ui.control.RadioButton
        NormalButton            matlab.ui.control.RadioButton
        UIAxes                  matlab.ui.control.UIAxes
    end

    
    properties (Access = public)
        k = 1;          % volgnummer figuur 
        output = [];     % matrix met 0 en 1
    end
    

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

        % Callback function
        function AmplitudeSliderValueChanged(app, event)
%             value = app.AmplitudeSlider.Value;
%             plot(app.UIAxes, value*peaks)
%             app.UIAxes.YLim = [-1000 1000];
        end

        % Callback function: BeoordelingButtonGroup, UIFigure
        function ImageClicked(app, event)

        end

        % Selection changed function: BeoordelingButtonGroup
        function BeoordelingButtonGroupSelectionChanged(app, event)

        end

        % Button pushed function: NextButton
        function NextButtonPushed(app, event)
            
            
            % volgende figuur in de lijst
            app.k = app.k+1;
            
            % locatie figuur
            filepath = '/Users/galiaanguelova/Downloads/nieuwEEGs_Marleen_2023_07/Figuren_seizureLocation_selectie_deel2_nolegend/';
            filename = ['Figuur_',num2str(app.k),'_2023_09_15.png'];
            fullname = [filepath, filename];
            
            % show new image
            ImageFile = imread(fullname);
            imagesc(app.UIAxes, ImageFile);
            
            if app.NormalButton.Value == true
                app.output = [app.output; 0];
            
            elseif app.EpilepticButton.Value == true
                app.output = [app.output; 1];
                
            end
            
            EEG_output = app.output;
            save('/Users/galiaanguelova/Downloads/nieuwEEGs_Marleen_2023_07/output_seizureLocation_selectie_deel2_2023_09_15.mat','EEG_output')

        end

        % Button pushed function: StartButton
        function StartButtonPushed(app, event)
%             cd /Users/galiaanguelova/Downloads/tryout/Ambulatory_Epi/Figuren_seizureLocation_selectie_zonder1042_nolegend/
%             app.k=1;
%             app.output = []
            filepath = '/Users/galiaanguelova/Downloads/nieuwEEGs_Marleen_2023_07/Figuren_seizureLocation_selectie_deel2_nolegend/';
            filename = ['Figuur_',num2str(app.k),'_2023_09_15.png'];
            fullname = [filepath, filename];
            
%             f = uifigure;
%             im = uiimage(f);
%             im.ImageSource = txt;
%             app.Image = uiimage(txt);
%             app.UIFigure = txt;

%             imshow(fullname)

           ImageFile = imread(fullname);
           imagesc(app.UIAxes, ImageFile);
           
        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 640 480];
            app.UIFigure.Name = 'MATLAB App';
            app.UIFigure.KeyPressFcn = createCallbackFcn(app, @ImageClicked, true);

            % Create UIAxes
            app.UIAxes = uiaxes(app.UIFigure);
            app.UIAxes.TickLabelInterpreter = 'none';
            app.UIAxes.XTick = [];
            app.UIAxes.XTickLabel = {'0'; '0.5'; '1'};
            app.UIAxes.YTick = [];
            app.UIAxes.YTickLabel = {'0'; '0.1'; '0.2'; '0.3'; '0.4'; '0.5'; '0.6'; '0.7'; '0.8'; '0.9'; '1'};
            app.UIAxes.ZTick = [];
            app.UIAxes.Position = [119 1 164 480];

            % Create BeoordelingButtonGroup
            app.BeoordelingButtonGroup = uibuttongroup(app.UIFigure);
            app.BeoordelingButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @BeoordelingButtonGroupSelectionChanged, true);
            app.BeoordelingButtonGroup.Title = 'Beoordeling';
            app.BeoordelingButtonGroup.ButtonDownFcn = createCallbackFcn(app, @ImageClicked, true);
            app.BeoordelingButtonGroup.Position = [390 238 100 75];

            % Create NormalButton
            app.NormalButton = uiradiobutton(app.BeoordelingButtonGroup);
            app.NormalButton.Text = 'Normal';
            app.NormalButton.Position = [11 29 61 22];
            app.NormalButton.Value = true;

            % Create EpilepticButton
            app.EpilepticButton = uiradiobutton(app.BeoordelingButtonGroup);
            app.EpilepticButton.Text = 'Epileptic';
            app.EpilepticButton.Position = [11 7 68 22];

            % Create NextButton
            app.NextButton = uibutton(app.UIFigure, 'push');
            app.NextButton.ButtonPushedFcn = createCallbackFcn(app, @NextButtonPushed, true);
            app.NextButton.Position = [390 169 100 22];
            app.NextButton.Text = 'Next';

            % Create StartButton
            app.StartButton = uibutton(app.UIFigure, 'push');
            app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
            app.StartButton.Position = [390 396 100 22];
            app.StartButton.Text = 'Start';

            % 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_2023_09_15

            % Create UIFigure and components
            createComponents(app)

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

            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