classdef app2 < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                       matlab.ui.Figure
        TabGroup                       matlab.ui.container.TabGroup
        GeneralTab                     matlab.ui.container.Tab
        PlotSettingsPanel              matlab.ui.container.Panel
        ndyAxisCheckBox                matlab.ui.control.CheckBox
        xAxisDropDownLabel             matlab.ui.control.Label
        ResetSubplotButton             matlab.ui.control.Button
        PlotSubplotButton              matlab.ui.control.Button
        ButtonGroup                    matlab.ui.container.ButtonGroup
        button_timestamped             matlab.ui.control.ToggleButton
        button_stint                   matlab.ui.control.ToggleButton
        Panel_2                        matlab.ui.container.Panel
        SelectedSubplotEditFieldLabel  matlab.ui.control.Label
        Field_NoSP                     matlab.ui.control.NumericEditField
        textfield                      matlab.ui.control.EditField
        Field_SelectedSP               matlab.ui.control.NumericEditField
        FeaturesPanel                  matlab.ui.container.Panel
        yAxisTitleLabel_2              matlab.ui.control.Label
        CustomxAxisLabel               matlab.ui.control.Label
        yAxisTitle_2                   matlab.ui.control.EditField
        yAxisTitleLabel                matlab.ui.control.Label
        xAxisTitle                     matlab.ui.control.EditField
        CustomxAxisDropDown            matlab.ui.control.DropDown
        Panel_3                        matlab.ui.container.Panel
        UpperEditField                 matlab.ui.control.NumericEditField
        UpperEditFieldLabel            matlab.ui.control.Label
        LowerEditField                 matlab.ui.control.NumericEditField
        SetLimitsCheckBox              matlab.ui.control.CheckBox
        LowerEditFieldLabel            matlab.ui.control.Label
        LegendonCheckBox               matlab.ui.control.CheckBox
        GridonCheckBox                 matlab.ui.control.CheckBox
        yAxisTitle                     matlab.ui.control.EditField
        yAxisLabel                     matlab.ui.control.Label
        xAxisDropDown                  matlab.ui.control.DropDown
        SubplotTitle                   matlab.ui.control.EditField
        SubplotTitleEditFieldLabel     matlab.ui.control.Label
        OverallTitleField              matlab.ui.control.EditField
        TitleLabel                     matlab.ui.control.Label
        ColumnsLabel                   matlab.ui.control.Label
        FigureTitleCheckBox            matlab.ui.control.CheckBox
        RowsEditField                  matlab.ui.control.NumericEditField
        ColumnsEditField               matlab.ui.control.NumericEditField
        RowsLabel                      matlab.ui.control.Label
        DataManipulationandExtraFunctionsPanel  matlab.ui.container.Panel
        ExtFunctionsDropDownLabel      matlab.ui.control.Label
        ApplyFunctionButton            matlab.ui.control.Button
        SearchEditField_3Label         matlab.ui.control.Label
        ExtFunctionsDropDown           matlab.ui.control.DropDown
        GeoplotwithPowerButton         matlab.ui.control.Button
        GeoplotButton                  matlab.ui.control.Button
        CalcPowerButton                matlab.ui.control.Button
        CreatedListBox                 matlab.ui.control.ListBox
        CreatedListBoxLabel            matlab.ui.control.Label
        ExportButton_2                 matlab.ui.control.Button
        ChooseDatasetstouseListBoxLabel  matlab.ui.control.Label
        AppendButton                   matlab.ui.control.Button
        ClearButton_2                  matlab.ui.control.Button
        Filteringusingmedfilt1Panel    matlab.ui.container.Panel
        FilterButton                   matlab.ui.control.Button
        VisualizeSwitch                matlab.ui.control.Switch
        VisualizeSwitchLabel           matlab.ui.control.Label
        DeviationEditFieldLabel        matlab.ui.control.Label
        DeviationEditField             matlab.ui.control.NumericEditField
        NeighborsSpinner               matlab.ui.control.Spinner
        HelpButton                     matlab.ui.control.Button
        NeighborsSpinnerLabel          matlab.ui.control.Label
        SearchEditField_3              matlab.ui.control.EditField
        ChooseDatasetstouseListBox     matlab.ui.control.ListBox
        SetTimestampsPanel             matlab.ui.container.Panel
        relTimeCheckBox                matlab.ui.control.CheckBox
        StopLabel                      matlab.ui.control.Label
        StartLabel                     matlab.ui.control.Label
        Label_4                        matlab.ui.control.Label
        Label_3                        matlab.ui.control.Label
        Label_2                        matlab.ui.control.Label
        Label                          matlab.ui.control.Label
        TimestampedListBox             matlab.ui.control.ListBox
        TimestampedListBoxLabel        matlab.ui.control.Label
        DateDropDownLabel              matlab.ui.control.Label
        ExportButton_3                 matlab.ui.control.Button
        ClearButton_3                  matlab.ui.control.Button
        ApplyButton                    matlab.ui.control.Button
        end_s                          matlab.ui.control.NumericEditField
        end_m                          matlab.ui.control.NumericEditField
        end_h                          matlab.ui.control.NumericEditField
        start_s                        matlab.ui.control.NumericEditField
        start_m                        matlab.ui.control.NumericEditField
        start_h                        matlab.ui.control.NumericEditField
        DateDropDown                   matlab.ui.control.DropDown
        UseCustomTimestampsCheckBox    matlab.ui.control.CheckBox
        Laps                           matlab.ui.control.ListBox
        LapsiffoundListBoxLabel        matlab.ui.control.Label
        DataPanel                      matlab.ui.container.Panel
        AvailableDatasetsListBox       matlab.ui.control.ListBox
        SelectDataLabel                matlab.ui.control.Label
        SearchEditField_2Label         matlab.ui.control.Label
        SearchEditField_2              matlab.ui.control.EditField
        SearchEditFieldLabel           matlab.ui.control.Label
        LoadedDatasetsListBox          matlab.ui.control.ListBox
        LoadedDatasetsListBoxLabel     matlab.ui.control.Label
        ExportButton                   matlab.ui.control.Button
        ClearButton                    matlab.ui.control.Button
        LoadDatasetButton              matlab.ui.control.Button
        SearchEditField                matlab.ui.control.EditField
        PresetsTab                     matlab.ui.container.Tab
        EditField_2                    matlab.ui.control.EditField
        ApplySeasonButton              matlab.ui.control.Button
        Preset                         matlab.ui.control.DropDown
        LoadPresetsButton              matlab.ui.control.Button
        QuickStatsTextArea             matlab.ui.control.TextArea
        QuickStatsTextAreaLabel        matlab.ui.control.Label
        PlottypeLabel                  matlab.ui.control.Label
        PlotsDropDown                  matlab.ui.control.DropDown
        ButtonGroup_2                  matlab.ui.container.ButtonGroup
        button_timestamped_2           matlab.ui.control.ToggleButton
        button_stint_2                 matlab.ui.control.ToggleButton
        PlotPresetsButton              matlab.ui.control.Button
        SetTimestampsPanel_2           matlab.ui.container.Panel
        xAxisDropDown_2Label           matlab.ui.control.Label
        xAxisDropDown_2                matlab.ui.control.DropDown
        StopLabel_2                    matlab.ui.control.Label
        StartLabel_2                   matlab.ui.control.Label
        Label_8                        matlab.ui.control.Label
        Label_7                        matlab.ui.control.Label
        Label_6                        matlab.ui.control.Label
        Label_5                        matlab.ui.control.Label
        end_s_2                        matlab.ui.control.NumericEditField
        end_m_2                        matlab.ui.control.NumericEditField
        end_h_2                        matlab.ui.control.NumericEditField
        start_s_2                      matlab.ui.control.NumericEditField
        start_m_2                      matlab.ui.control.NumericEditField
        start_h_2                      matlab.ui.control.NumericEditField
        DateDropDown_2Label            matlab.ui.control.Label
        DateDropDown_2                 matlab.ui.control.DropDown
        UseCustomTimestampsCheckBox_2  matlab.ui.control.CheckBox
        Laps_2                         matlab.ui.control.ListBox
        LapsiffoundListBoxLabel_2      matlab.ui.control.Label
        SaveButton                     matlab.ui.control.Button
        Format                         matlab.ui.control.DropDown
        savename                       matlab.ui.control.EditField
        PlotPanel                      matlab.ui.container.Panel
        Image                          matlab.ui.control.Image
        StatusTextArea                 matlab.ui.control.TextArea
        StatusTextAreaLabel            matlab.ui.control.Label
        LoadAvailableButton            matlab.ui.control.Button
        EditField                      matlab.ui.control.EditField
        BrowseButton                   matlab.ui.control.Button
        ContextMenu                    matlab.ui.container.ContextMenu
        CopyMenu                       matlab.ui.container.Menu
    end

    
    properties (Access = public)
        % initialize global variables
        filepath_last = "none";
        filepath = "none";
        fns = "none";
        data = timetable();
        data_created = timetable();
        data_tr = timetable();
        pltData = timetable();
        tr = timerange();
        tr_preset = timerange();
        fig = [];
        timestamp = datetime();
        timestamp_index = [];
        folder = 0;
        laps_strArray = string();
        folder_name = string();
        stats = struct();
    end
    
    methods (Access = private)

        % browse: choose file to load (place .mat file into data)
        function browse(app)
            %create a dummy figure so that uigetfile doesn't minimize our GUI
            f = figure('Renderer', 'painters', 'Position', [-100 -100 0 0]); 
            
            % actual browse function
            [name, location] = uigetfile(...
                {'*.m;*.mat',...
                'MATLAB Files (*.m,*.mat)';
                '*.*',  'All Files (*.*)'}, ...
                "Select File","data\");
            app.filepath = append(location,name);
            app.EditField.Value = app.filepath;

            %delete the dummy figure
            delete(f); 
        end

        function preview_data(app)
            % check if data is already loaded
            if strcmp(app.filepath, app.filepath_last) == false
                % load data via vector2timetable (see podio)
                data_fn = load(app.filepath);
                % generate list of all avaible data
                app.fns = fieldnames(data_fn);
                app.AvailableDatasetsListBox.Items = app.fns.';
                func_all = dir("functions\*.m");
                func_name = string();
                for i=1:length(func_all)
                    func_name(i) = func_all(i).name;
                    func_name(i) = erase(func_name(i), ".m");
                end
                app.ExtFunctionsDropDown.Items = func_name.';
            else
                msgbox("Data already loaded!");
            end
            app.filepath_last = app.filepath;
        end
        
        % loads chosen data with vector2timetable
        function load_pdata(app, fn)
            % read data if no data is loaded
            if isempty(app.data)
                app.data = vector2timetable(app.filepath, fn{:});
            % if data is loaded add to already existing and synchronize lengths
            else
                add_data = vector2timetable(app.filepath, fn{:});
                app.data = synchronize(app.data, add_data,"union","nearest");
            end
            % update date
            dates = dateshift(app.data.Time, "start", "day");
            dates = unique(dates);
            app.DateDropDown.Items = string(dates);
            app.DateDropDown.ItemsData = dates;
            app.DateDropDown_2.Items = string(dates);
            app.DateDropDown_2.ItemsData = dates;
        end

        % load: loads data based on default configuration (ABX,Shunt,...)
        % and generates list of all data avaible (might need to change
        % according to season)
        function load_data_presets(app)
            preview_data(app);
            load_pdata(app,["ABX*","Shunt*","AMS_Status*","FTCU_*","INV*", "*_10Hz_*", "*_100Hz_*","VN200*", "XSens*"])
            % update date
            dates = dateshift(app.data.Time, "start", "day");
            dates = unique(dates);
            app.DateDropDown.Items = string(dates);
            app.DateDropDown.ItemsData = dates;
            app.DateDropDown_2.Items = string(dates);
            app.DateDropDown_2.ItemsData = dates;
            app.pltData = app.data;
        end

        function laptime(app)
            % load Laptime Counter
            data_lt = vector2timetable(app.filepath, "ABX_Driver_ABX_Lapcounter", "FTCU_Driver_FTCU_Lapcounter");
            %get date / time
            date = dateshift(data_lt.Time(1),'start','day');
            
            % get lapcounter / laptrigger
            laps_counter = data_lt.(data_lt.Properties.VariableNames{1});
            app.timestamp(1) = data_lt.Time(1);
            app.timestamp_index(1) = 1;
            j = 2;
            for i = 2:length(laps_counter)
                if laps_counter(i) ~= laps_counter(i-1)
                    app.timestamp(j) = data_lt.Time(i);
                    app.timestamp_index(j) = i;
                    j = j + 1;
                end
            end
        
            % calculate laptimes
            for i = 1:length(app.timestamp)-1
                timestamp_s(i) = app.timestamp(i+1) - app.timestamp(i);
            end
            laps_s = seconds(timestamp_s);
            % if laps could be detected find fastest lap and create list of
            % laptimes, otherwise only "Entire stint" will be selectable
            if (exist("laps_s","var") == true)
                % create list of laptimes
                for i = 1:length(laps_s)
                    if laps_s(i) == min(laps_s)
                        app.laps_strArray(i) = sprintf("Lap %d: %.3fs (best)",i,laps_s(i));
                    else
                        app.laps_strArray(i) = sprintf("Lap %d: %.3fs",i,laps_s(i));
                    end
                end
            end
        end
        
        % search function for list
        function search(app, changingValue, source)
            % If empty reset list
            if isempty(changingValue) 
                app.AvailableDatasetsListBox.Items = app.fns.'; % whole dataset
                app.LoadedDatasetsListBox.Items = app.data.Properties.VariableNames(:); % loaded datasets
                app.ChooseDatasetstouseListBox.Items = app.data.Properties.VariableNames(:);  % loaded datasets
            else
                % search function for the sourced which called it
                if source == 3
                    idx = contains(app.ChooseDatasetstouseListBox.Items, changingValue);
                    Filtered_Values = app.ChooseDatasetstouseListBox.Items(idx);
                    app.ChooseDatasetstouseListBox.Items = Filtered_Values;
                elseif source == 2
                    idx = contains(app.LoadedDatasetsListBox.Items, changingValue);
                    Filtered_Values = app.LoadedDatasetsListBox.Items(idx);
                    app.LoadedDatasetsListBox.Items = Filtered_Values;
                else
                    idx = contains(app.AvailableDatasetsListBox.Items, changingValue);
                    Filtered_Values = app.AvailableDatasetsListBox.Items(idx);
                    app.AvailableDatasetsListBox.Items = Filtered_Values;
                end
            end 
        end

    function data_filter = medFil(app, data)
        data_filter = data;
        for i=1:width(data)
            medianSignal = medfilt1(data.(data.Properties.VariableNames{i}), app.NeighborsSpinner.Value);
            diffSignal = abs(data.(data.Properties.VariableNames{i}) - medianSignal);
            spikes = diffSignal > app.DeviationEditField.Value;
            % Replace
            fixedSignal = data.(data.Properties.VariableNames{i}); % Initialize
            fixedSignal(spikes) = medianSignal(spikes);
            data_filter.(data_filter.Properties.VariableNames{i}) = fixedSignal;
            if app.VisualizeSwitch.Value == "On"
                figure(i+2)
                subplot(3,1,1)
                plot(data.Time, data.(data.Properties.VariableNames{i}))
                title("Original");
                hold on
                subplot(3,1,2)
                plot(data.Time, spikes, "x")
                title("Index of changed values")
                subplot(3,1,3)
                plot(data.Time, fixedSignal)
                title("Filtered Data")
            end
        end
    end

        % update Listbox Items
        function update(app)
            app.LoadedDatasetsListBox.Items = app.data.Properties.VariableNames(:);
            app.ChooseDatasetstouseListBox.Items = app.data.Properties.VariableNames(:);
            app.CreatedListBox.Items = app.data_created.Properties.VariableNames(:);
            app.CustomxAxisDropDown.Items = app.data.Properties.VariableNames(:);
        end

        
        function apply_func(app)
            func_call = str2func(app.ExtFunctionsDropDown.Value);
            for i=1:length(app.ChooseDatasetstouseListBox.Value)
                data_cell{i} = app.data.(app.ChooseDatasetstouseListBox.Value{i});
            end
            n_out = nargout(func_call);
            func_data = cell(1,n_out);
            [func_data{:}] = func_call(data_cell{:});
            app.data_created = addvars(app.data_created, func_data{2:end}, NewVariableNames=func_data{1});
            if all(isnat(app.data_created.Time));
                app.data_created.Time = app.data.Time;
            end
        end
        
        function [time_hms, time_hms_r] = conv_hms(app, data)
            if app.button_timestamped.Value == true 
                date = app.DateDropDown.Value;
            else
                date = dateshift(data,'start','day');
            end
            time_hms = data-date;
            time_hms_r = time_hms - time_hms(1);
        end
        
        function [time_s, time_s_r] = conv_s(app, data)
            time_hms = conv_hms(app,data);
            time_s = seconds(time_hms);
            time_s_r = time_s - time_s(1); % set beginning of session to 0
        end

        function distance_m = distance(app, data)
            
        end
        
        
        function geoplot(app)
            try
                hold off
                geoplot(app.data.XSens_LongLat_XSens_latitude, app.data.XSens_LongLat_XSens_longitude, "r");
                geobasemap satellite;
            end
        end
end
    methods (Access = public)

        % startup function to set additional paths and icons
        function startup(app)
            addpath("assets\");
            addpath("functions\");
            app.UIFigure.Icon = "FT_icon.png";
            pathing(app)
        end

        % add and remove paths depending on choosen 
        function pathing(app)
            d = dir("season");
            % remove all files (isdir property is 0)
            dfolders = d([d(:).isdir]) 
            % remove '.' and '..' 
            dfolders = dfolders(~ismember({dfolders(:).name},{'.','..'}))
            app.folder_name = string();
            for i=1:length(dfolders)
                app.folder_name(i) = dfolders(i).name;
            end
            app.folder_name = flip(app.folder_name.')
            app.Preset.Items = app.folder_name;
            if app.folder ~= 0
                rmpath("season\"+ app.folder_name(app.folder));
                rmpath("season\"+ app.folder_name(app.folder) + "\plot_settings");
            end
            addpath("season\"+app.folder_name(app.Preset.ValueIndex));
            addpath("season\"+app.folder_name(app.Preset.ValueIndex) + "\plot_settings");
            app.folder = app.Preset.ValueIndex;
        end

        function pathing_change(app)
        if app.folder ~= 0
            rmpath("season\"+ app.folder_name(app.folder));
            rmpath("season\"+ app.folder_name(app.folder) + "\plot_settings");
        end
        app.folder = app.Preset.ValueIndex;
        addpath("season\"+app.folder_name(app.Preset.ValueIndex));
        addpath("season\"+app.folder_name(app.Preset.ValueIndex) + "\plot_settings");
        end

        % set timerange for data either with custom, selected lap or entire stint
        function set_tr(app)
            app.tr = timerange(app.data.Time(1), app.data.Time(end));
            if app.UseCustomTimestampsCheckBox.Value == 1
                date = string(app.DateDropDown.Value);
                start = date + " " + string(app.start_h.Value) + ":" + string(app.start_m.Value) + ":"  + string(app.start_s.Value);
                stop = date + " " + string(app.end_h.Value) + ":"  + string(app.end_m.Value) + ":"  + string(app.end_s.Value);
                app.tr = timerange(start, stop);
                app.data_tr = app.data(app.tr,:);
            else %selected lap
                start = app.timestamp(app.Laps.ValueIndex);
                stop = app.timestamp(app.Laps.ValueIndex+1);
                app.tr = timerange(start,stop,"closed");
                app.data_tr = app.data(app.tr,:);
            end
            app.TimestampedListBox.Items = app.data_tr.Properties.VariableNames(:);
        end

        function set_tr_preset(app)
            app.tr_preset = timerange(app.pltData.Time(1), app.pltData.Time(end));
            if app.UseCustomTimestampsCheckBox_2.Value == 1
                date = string(app.DateDropDown_2.Value);
                start = date + " " + string(app.start_h_2.Value) + ":" + string(app.start_m_2.Value) + ":"  + string(app.start_s_2.Value);
                stop = date + " " + string(app.end_h_2.Value) + ":"  + string(app.end_m_2.Value) + ":"  + string(app.end_s_2.Value);
                app.tr_preset = timerange(start, stop);
            else %selected lap
                start = app.timestamp(app.Laps_2.ValueIndex);
                stop = app.timestamp(app.Laps_2.ValueIndex+1);
                app.tr_preset = timerange(start,stop,"closed");
            end
        end

        % adds subplots in figure(1)
        function subplotting(app)

            % pltData is chosen from entire stint or timestamp
            if app.button_timestamped.Value == true 
                local_pltData = app.data_tr;
                fns_plot = app.TimestampedListBox.Value;
            else
                local_pltData = app.data;
                fns_plot = app.LoadedDatasetsListBox.Value;
            end
            

            % set xAxis Values
            tmp = [];
            switch app.xAxisDropDown.Value
                case "Time [h:m:s + Date]"
                    xAxis = local_pltData.Time;
                case "Time [h:m:s]"
                    if app.relTimeCheckBox.Value == 1
                        [tmp, xAxis] = conv_hms(app, local_pltData.Time);
                        label_x = "relative Zeit in h:m:s";
                    else
                        [xAxis, tmp] = conv_hms(app, local_pltData.Time);
                        label_x = "Uhrzeit in h:m:s";
                    end
                case "Time [s]"
                    if app.relTimeCheckBox.Value == 1
                        [tmp, xAxis] = conv_s(app, local_pltData.Time);
                        label_x = "relative Zeit in s";
                    else
                        [xAxis, tmp] = conv_s(app, local_pltData.Time);
                        label_x = "Uhrzeit in s";
                    end
                case "Distance [m]"
                    xAxis = distance(app, local_pltData.Time);
                    label_x = "Weg in m";
                case "Custom"
                    xAxis = local_pltData.(app.CustomxAxisDropDown.Value);
                otherwise
                    xAxis = local_pltData.Time;
            end


            figure(1)
            hold on

            % Plotting
            for i=1:length(fns_plot)
                app.fig(app.Field_SelectedSP.Value) = subplot(app.ColumnsEditField.Value, app.RowsEditField.Value, app.Field_SelectedSP.Value)
                plot(xAxis, local_pltData.(fns_plot{i}));
            end

            % Title for the Subplot
            title(app.SubplotTitle.Value);
            % Legend
            if app.LegendonCheckBox.Value == 1
                legend(fns_plot, 'Interpreter', 'none')
            end
            % Overall Title if multiple Subplots
            if app.FigureTitleCheckBox.Value == 1
                sgtitle(app.OverallTitleField.Value)
            end
            if app.GridonCheckBox.Value == 1
                grid on
            end

            % check 
            if app.ndyAxisCheckBox.Value == 1
                yyaxis left
            end
            ylabel(app.yAxisTitle.Value);

            try
                xlabel(label_x);
            end
            if ~isempty(app.xAxisTitle.Value)
                xlabel(app.xAxisTitle.Value);
            end

            if app.SetLimitsCheckBox.Value == 1
                ylim([app.LowerEditField.Value app.UpperEditField.Value])
            end

            if app.ndyAxisCheckBox.Value == 1
                fns2 = app.ChooseDatasetstouseListBox.Value;
                yyaxis right
                for i=1:length(fns2)
                    plot(xAxis, local_pltData.(fns2{i}));
                end
                if app.LegendonCheckBox.Value == 1
                    legend([fns fns2], 'Interpreter', 'none')
                end
                if app.SetLimitsCheckBox.Value == 1
                    ylim([app.LowerEditField.Value app.UpperEditField.Value])
                end
                ylabel(app.yAxisTitle_2.Value);
            end
        end

    end
    

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

        % Code that executes after component creation
        function startupFcn(app)
            startup(app);
        end

        % Button pushed function: BrowseButton
        function BrowseButtonPushed(app, event)
            browse(app);
        end

        % Button pushed function: LoadAvailableButton
        function LoadAvailableButtonPushed(app, event)
            % quickloads all fieldnames
            app.StatusTextArea.Value = "Loading...";
            pause(0.01);
            preview_data(app);
            laptime(app);
            app.Laps.Items = app.laps_strArray.';
            app.Laps.ItemsData = app.timestamp_index;
            app.Laps_2.Items = app.laps_strArray.';
            app.Laps_2.ItemsData = app.timestamp_index;
            pause(0.01);
            app.StatusTextArea.Value = "Finished Loading";
            pause(0.01);
        end

        % Value changed function: Preset
        function PresetValueChanged(app, event)
            pathing_change(app)
        end

        % Button pushed function: LoadDatasetButton
        function LoadDatasetButtonPushed(app, event)
            % loads chosen datasets into app(!) workspace and the names into listboxes
            app.StatusTextArea.Value = "Loading chosen datasets...";
            pause(0.01);
            load_pdata(app, app.AvailableDatasetsListBox.Value) 
            app.LoadedDatasetsListBox.Items = app.data.Properties.VariableNames(:);
            update(app);
            app.StatusTextArea.Value = "Finished loading datasets";
            pause(0.01);
        end

        % Value changing function: SearchEditField, SearchEditField_2, 
        % ...and 1 other component
        function SearchEditFieldValueChanging(app, event)
            % checks source which triggered search
            changingValue = event.Value;
            if event.Source.Tag == "search3"
                source = 3;
            elseif event.Source.Tag == "search2"
                source = 2;
            else
                source = 1;
            end
            search(app, changingValue, source)
        end

        % Button pushed function: ClearButton
        function ClearButtonPushed(app, event)
            % clears data from app(!) workspace
            app.data = timetable();
            app.LoadedDatasetsListBox.Items = {};
            app.ChooseDatasetstouseListBox.Items = {};
        end

        % Button pushed function: ExportButton
        function ExportButtonPushed(app, event)
            % exports all data into Matlab(!) workspace
            assignin("base", "data", app.data);
        end

        % Button pushed function: FilterButton
        function FilterButtonPushed(app, event)
            app.StatusTextArea.Value = "Creating new dataset to filter...";
            pause(0.01);
            for i=1:length(app.ChooseDatasetstouseListBox.Value)
                if i==1
                    data_filtered = app.data(:,app.ChooseDatasetstouseListBox.Value(i));
                else
                    data_filtered = synchronize(data_filtered, app.data(:,app.ChooseDatasetstouseListBox.Value(i)), "union", "nearest");
                end
            end
            app.StatusTextArea.Value = "Filtering ...";
            pause(0.01);
            app.data_created = medFil(app, data_filtered);
            newNames = append("filtered_", app.data_created.Properties.VariableNames(:));
            app.data_created = renamevars(app.data_created, app.data_created.Properties.VariableNames(:), newNames);
            update(app);
            app.StatusTextArea.Value = "Done Filtering!"
            pause(0.01);
        end

        % Button pushed function: ApplyFunctionButton
        function ApplyFunctionButtonPushed(app, event)
            app.StatusTextArea.Value = "Applying Function..." 
            pause(0.01);
            apply_func(app);
            update(app);
            app.StatusTextArea.Value = "Applied Function!"
        end

        % Button pushed function: HelpButton
        function HelpButtonPushed(app, event)
            msgbox("Neigbors: Looks at the number of numbers to compare it to, orient yourself at the sampling frequency. Keep empty to not use it. \n Deviation: Expected deviation to filter");
        end

        % Button pushed function: ClearButton_2
        function ClearButton_2Pushed(app, event)
            app.data_created = timetable();
            app.CreatedListBox.Items = {};
        end

        % Button pushed function: AppendButton
        function AppendButtonPushed(app, event)
            app.StatusTextArea.Value = "Appending...";
            pause(0.01);
            try
                app.data = [app.data app.data_created(:,app.CreatedListBox.Value(:))];
            catch
                app.StatusTextArea.Value = "Appending failed, trying to synchronize...";
                pause(0.01);
                app.data = synchronize(app.data, app.data_created, "union", "nearest");
            end
            app.StatusTextArea.Value = "Done appending...";
            update(app);
        end

        % Button pushed function: ExportButton_2
        function ExportButton_2Pushed(app, event)
            % exports created data into Matlab(!) workspace
            assignin("base", "data_created", app.data_created);
        end

        % Button pushed function: ClearButton_3
        function ClearButton_3Pushed(app, event)
            app.data_tr = timetable();
            app.TimestampedListBox.Items = {};
        end

        % Button pushed function: ExportButton_3
        function ExportButton_3Pushed(app, event)
            assignin("base", "data_tr", app.data_tr);
        end

        % Button pushed function: ApplyButton
        function ApplyButtonPushed(app, event)
            app.StatusTextArea.Value = "Setting Timerange...";
            pause(0.01);
            set_tr(app);
            app.StatusTextArea.Value = "Done!";
        end

        % Value changed function: FigureTitleCheckBox
        function FigureTitleCheckBoxValueChanged(app, event)
            app.OverallTitleField.Enable = app.FigureTitleCheckBox.Value;
        end

        % Value changed function: ColumnsEditField, RowsEditField
        function NumSP(app, event)
            % changes the number that indicates the number of subplots
            rows = app.RowsEditField.Value;
            cols = app.ColumnsEditField.Value;
            app.Field_NoSP.Value = rows * cols;
        end

        % Button pushed function: PlotSubplotButton
        function PlotSubplotButtonPushed(app, event)
            app.StatusTextArea.Value = "Plotting...";
            pause(0.01);
            subplotting(app);
            app.StatusTextArea.Value = "Finished Plotting";
            pause(0.01);
        end

        % Button pushed function: ResetSubplotButton
        function ResetSubplotButtonPushed(app, event)
                delete(app.fig(app.Field_SelectedSP.Value));
        end

        % Button pushed function: GeoplotButton
        function GeoplotButtonPushed(app, event)
            app.StatusTextArea.Value = "Plotting map...";
            pause(0.01);
            geoplot(app);
            app.StatusTextArea.Value = "Finished Plotting";
        end

        % Button pushed function: LoadPresetsButton
        function LoadPresetsButtonPushed(app, event)
            app.StatusTextArea.Value = "Loading (might take a few minutes) ...";
            pause(0.01);
            laptime(app);
            app.Laps.Items = app.laps_strArray.';
            app.Laps.ItemsData = app.timestamp_index;
            app.Laps_2.Items = app.laps_strArray.';
            app.Laps_2.ItemsData = app.timestamp_index;
            pause(0.01);
            load_data_presets(app);
            app.LoadedDatasetsListBox.Items = app.data.Properties.VariableNames(:);
            app.QuickStatsTextArea.Value = "Loaded:" + app.data.Properties.VariableNames(:);
            app.StatusTextArea.Value = "Finished Loading";
            pause(0.01);
        end

        % Button pushed function: ApplySeasonButton
        function ApplySeasonButtonPushed(app, event)
            app.StatusTextArea.Value = "Applying seasonal preset...";
            pause(0.01)
            [app.pltData, app.stats] = sortdata(app.pltData);
            app.QuickStatsTextArea.Value = sidebar_stats(app.stats);
            app.StatusTextArea.Value = "Done!";
        end

        % Button pushed function: PlotPresetsButton
        function PlotPresetsButtonPushed(app, event)
            % switch to selected x-Axis
            switch app.xAxisDropDown_2.Value
                case "Time [h:m:s+Date]"
                    app.pltData.xAxis = app.pltData.Time;
                case "Time [h:m:s]"
                    app.pltData.xAxis = app.pltData.time_hms;
                case "Time [s]"
                    app.pltData.xAxis = app.pltData.time_s;
                case "Distance [m]"
                    app.pltData.xAxis = app.pltData.distance;
                otherwise
                    error("Error plotting")
            end
            
            app.StatusTextArea.Value = "Loading plot...";
            pause(0.01)
            
            if app.button_timestamped_2.Value == true 
                set_tr_preset(app)
            else
                app.tr_preset = timerange(app.pltData.Time(1), app.pltData.Time(end));
            end
            tr = app.tr_preset;

            switch app.PlotsDropDown.Value
                case "Accumulator"
                    plot_accumulator(app.PlotPanel, app.pltData, tr);
                case "Brakes"
                    plot_brakes(app.PlotPanel, app.pltData, tr);
                case "Driver - Braking"
                    plot_driver_braking(app.PlotPanel, app.pltData, tr);
                case "Driver - General"
                    plot_driver_general(app.PlotPanel, app.pltData, tr);
                case "Driver - Statistics"
                    plot_driver_statistics(app.PlotPanel, app.pltData, tr);
                case "Driver - Steering"
                    plot_driver_steering(app.PlotPanel, app.pltData, tr);
                case "Inverter"
                    plot_inverter(app.PlotPanel, app.pltData, tr);
                case "Powertrain"
                    plot_powertrain(app.PlotPanel, app.pltData, tr);
                case "Suspension - Histogram"
                    plot_suspension_histogram(app.PlotPanel, app.pltData, tr);
                case "Suspension - Positions"
                    plot_suspension_positions(app.PlotPanel, app.pltData, tr);
                case "Suspension - Velocities"
                    plot_suspension_velocities(app.PlotPanel, app.pltData, tr);
                case "Tires - Friction Circle"
                    plot_tires_firctionCircle(app.PlotPanel, app.pltData, tr);
                case "Tires - Temperatures"
                    plot_tires_temperatures(app.PlotPanel, app.pltData, tr);
                case "Custom"
                    plot_custom(app.PlotPanel, app.pltData, tr);
                otherwise
                    error("Error plotting")
            end
            app.StatusTextArea.Value = "Finished plotting - " + app.PlotsDropDown.Value + "!";
        end

        % Menu selected function: CopyMenu
        function CopyMenuSelected(app, event)
            clipboard('copy', string(strjoin(app.AvailableDatasetsListBox.Value)));
        end

        % Button pushed function: SaveButton
        function SaveButtonPushed(app, event)
            try
                path = "exports\" + app.savename.Value;
                app.StatusTextArea.Value = "exporting...";
                savePlot(app.PlotPanel.Children, path, app.Format.Value);
                app.StatusTextArea.Value = "saved";
            catch
                msgbox("No plot available!")
            end
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Get the file path for locating images
            pathToMLAPP = fileparts(mfilename('fullpath'));

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

            % Create BrowseButton
            app.BrowseButton = uibutton(app.UIFigure, 'push');
            app.BrowseButton.ButtonPushedFcn = createCallbackFcn(app, @BrowseButtonPushed, true);
            app.BrowseButton.Position = [11 562 111 23];
            app.BrowseButton.Text = 'Browse';

            % Create EditField
            app.EditField = uieditfield(app.UIFigure, 'text');
            app.EditField.Position = [129 562 407 22];
            app.EditField.Value = '/data';

            % Create LoadAvailableButton
            app.LoadAvailableButton = uibutton(app.UIFigure, 'push');
            app.LoadAvailableButton.ButtonPushedFcn = createCallbackFcn(app, @LoadAvailableButtonPushed, true);
            app.LoadAvailableButton.Position = [552 561 114 23];
            app.LoadAvailableButton.Text = 'Load (Available)';

            % Create StatusTextAreaLabel
            app.StatusTextAreaLabel = uilabel(app.UIFigure);
            app.StatusTextAreaLabel.FontColor = [1 0 0];
            app.StatusTextAreaLabel.Position = [686 565 39 22];
            app.StatusTextAreaLabel.Text = 'Status';

            % Create StatusTextArea
            app.StatusTextArea = uitextarea(app.UIFigure);
            app.StatusTextArea.Editable = 'off';
            app.StatusTextArea.FontColor = [1 0 0];
            app.StatusTextArea.Position = [738 562 210 27];

            % Create Image
            app.Image = uiimage(app.UIFigure);
            app.Image.Enable = 'off';
            app.Image.Position = [1020 556 73 38];
            app.Image.ImageSource = fullfile(pathToMLAPP, 'assets', 'FT_logo.png');

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Position = [11 7 1093 540];

            % Create GeneralTab
            app.GeneralTab = uitab(app.TabGroup);
            app.GeneralTab.Title = 'General';

            % Create DataPanel
            app.DataPanel = uipanel(app.GeneralTab);
            app.DataPanel.Title = 'Data';
            app.DataPanel.Position = [7 312 525 199];

            % Create SearchEditField
            app.SearchEditField = uieditfield(app.DataPanel, 'text');
            app.SearchEditField.ValueChangingFcn = createCallbackFcn(app, @SearchEditFieldValueChanging, true);
            app.SearchEditField.Tag = 'search1';
            app.SearchEditField.Position = [56 7 200 22];

            % Create LoadDatasetButton
            app.LoadDatasetButton = uibutton(app.DataPanel, 'push');
            app.LoadDatasetButton.ButtonPushedFcn = createCallbackFcn(app, @LoadDatasetButtonPushed, true);
            app.LoadDatasetButton.Position = [158 150 99 23];
            app.LoadDatasetButton.Text = 'Load Dataset';

            % Create ClearButton
            app.ClearButton = uibutton(app.DataPanel, 'push');
            app.ClearButton.ButtonPushedFcn = createCallbackFcn(app, @ClearButtonPushed, true);
            app.ClearButton.FontColor = [1 0 0];
            app.ClearButton.Position = [394 151 47 23];
            app.ClearButton.Text = 'Clear';

            % Create ExportButton
            app.ExportButton = uibutton(app.DataPanel, 'push');
            app.ExportButton.ButtonPushedFcn = createCallbackFcn(app, @ExportButtonPushed, true);
            app.ExportButton.Position = [455 151 61 23];
            app.ExportButton.Text = 'Export';

            % Create LoadedDatasetsListBoxLabel
            app.LoadedDatasetsListBoxLabel = uilabel(app.DataPanel);
            app.LoadedDatasetsListBoxLabel.FontWeight = 'bold';
            app.LoadedDatasetsListBoxLabel.Position = [268 151 101 22];
            app.LoadedDatasetsListBoxLabel.Text = 'Loaded Datasets';

            % Create LoadedDatasetsListBox
            app.LoadedDatasetsListBox = uilistbox(app.DataPanel);
            app.LoadedDatasetsListBox.Items = {};
            app.LoadedDatasetsListBox.Multiselect = 'on';
            app.LoadedDatasetsListBox.Position = [267 37 250 108];
            app.LoadedDatasetsListBox.Value = {};

            % Create SearchEditFieldLabel
            app.SearchEditFieldLabel = uilabel(app.DataPanel);
            app.SearchEditFieldLabel.HorizontalAlignment = 'right';
            app.SearchEditFieldLabel.Position = [7 7 43 22];
            app.SearchEditFieldLabel.Text = 'Search';

            % Create SearchEditField_2
            app.SearchEditField_2 = uieditfield(app.DataPanel, 'text');
            app.SearchEditField_2.ValueChangingFcn = createCallbackFcn(app, @SearchEditFieldValueChanging, true);
            app.SearchEditField_2.Tag = 'search2';
            app.SearchEditField_2.Position = [317 7 200 22];

            % Create SearchEditField_2Label
            app.SearchEditField_2Label = uilabel(app.DataPanel);
            app.SearchEditField_2Label.HorizontalAlignment = 'right';
            app.SearchEditField_2Label.Position = [268 7 43 22];
            app.SearchEditField_2Label.Text = 'Search';

            % Create SelectDataLabel
            app.SelectDataLabel = uilabel(app.DataPanel);
            app.SelectDataLabel.FontWeight = 'bold';
            app.SelectDataLabel.Position = [8 151 111 22];
            app.SelectDataLabel.Text = 'Available Datasets';

            % Create AvailableDatasetsListBox
            app.AvailableDatasetsListBox = uilistbox(app.DataPanel);
            app.AvailableDatasetsListBox.Multiselect = 'on';
            app.AvailableDatasetsListBox.Position = [7 38 250 107];
            app.AvailableDatasetsListBox.Value = {'Item 1'};

            % Create SetTimestampsPanel
            app.SetTimestampsPanel = uipanel(app.GeneralTab);
            app.SetTimestampsPanel.Title = 'Set Timestamps';
            app.SetTimestampsPanel.Position = [541 312 540 199];

            % Create LapsiffoundListBoxLabel
            app.LapsiffoundListBoxLabel = uilabel(app.SetTimestampsPanel);
            app.LapsiffoundListBoxLabel.Position = [10 150 82 22];
            app.LapsiffoundListBoxLabel.Text = 'Laps (if found)';

            % Create Laps
            app.Laps = uilistbox(app.SetTimestampsPanel);
            app.Laps.Items = {};
            app.Laps.Position = [8 6 139 142];
            app.Laps.Value = {};

            % Create UseCustomTimestampsCheckBox
            app.UseCustomTimestampsCheckBox = uicheckbox(app.SetTimestampsPanel);
            app.UseCustomTimestampsCheckBox.Text = 'Use Custom Timestamps';
            app.UseCustomTimestampsCheckBox.Position = [153 151 156 22];

            % Create DateDropDown
            app.DateDropDown = uidropdown(app.SetTimestampsPanel);
            app.DateDropDown.Items = {};
            app.DateDropDown.Position = [190 123 125 22];
            app.DateDropDown.Value = {};

            % Create start_h
            app.start_h = uieditfield(app.SetTimestampsPanel, 'numeric');
            app.start_h.Limits = [0 23];
            app.start_h.ValueDisplayFormat = '%02.0f';
            app.start_h.Position = [190 89 30 22];

            % Create start_m
            app.start_m = uieditfield(app.SetTimestampsPanel, 'numeric');
            app.start_m.Limits = [0 59];
            app.start_m.ValueDisplayFormat = '%02.0f';
            app.start_m.HorizontalAlignment = 'center';
            app.start_m.Position = [238 89 30 22];

            % Create start_s
            app.start_s = uieditfield(app.SetTimestampsPanel, 'numeric');
            app.start_s.Limits = [0 59];
            app.start_s.ValueDisplayFormat = '%02.0f';
            app.start_s.Position = [283 89 32 22];

            % Create end_h
            app.end_h = uieditfield(app.SetTimestampsPanel, 'numeric');
            app.end_h.Limits = [0 23];
            app.end_h.ValueDisplayFormat = '%02.0f';
            app.end_h.HorizontalAlignment = 'center';
            app.end_h.Position = [190 56 30 22];

            % Create end_m
            app.end_m = uieditfield(app.SetTimestampsPanel, 'numeric');
            app.end_m.Limits = [0 59];
            app.end_m.ValueDisplayFormat = '%02.0f';
            app.end_m.HorizontalAlignment = 'center';
            app.end_m.Position = [238 56 30 22];

            % Create end_s
            app.end_s = uieditfield(app.SetTimestampsPanel, 'numeric');
            app.end_s.Limits = [0 59];
            app.end_s.ValueDisplayFormat = '%02.0f';
            app.end_s.HorizontalAlignment = 'center';
            app.end_s.Position = [283 56 32 22];

            % Create ApplyButton
            app.ApplyButton = uibutton(app.SetTimestampsPanel, 'push');
            app.ApplyButton.ButtonPushedFcn = createCallbackFcn(app, @ApplyButtonPushed, true);
            app.ApplyButton.Position = [238 15 78 23];
            app.ApplyButton.Text = 'Apply';

            % Create ClearButton_3
            app.ClearButton_3 = uibutton(app.SetTimestampsPanel, 'push');
            app.ClearButton_3.ButtonPushedFcn = createCallbackFcn(app, @ClearButton_3Pushed, true);
            app.ClearButton_3.FontColor = [1 0 0];
            app.ClearButton_3.Position = [408 151 48 23];
            app.ClearButton_3.Text = 'Clear';

            % Create ExportButton_3
            app.ExportButton_3 = uibutton(app.SetTimestampsPanel, 'push');
            app.ExportButton_3.ButtonPushedFcn = createCallbackFcn(app, @ExportButton_3Pushed, true);
            app.ExportButton_3.Position = [467 151 60 23];
            app.ExportButton_3.Text = 'Export';

            % Create DateDropDownLabel
            app.DateDropDownLabel = uilabel(app.SetTimestampsPanel);
            app.DateDropDownLabel.Position = [153 123 30 22];
            app.DateDropDownLabel.Text = 'Date';

            % Create TimestampedListBoxLabel
            app.TimestampedListBoxLabel = uilabel(app.SetTimestampsPanel);
            app.TimestampedListBoxLabel.FontWeight = 'bold';
            app.TimestampedListBoxLabel.Position = [321 151 82 22];
            app.TimestampedListBoxLabel.Text = 'Timestamped';

            % Create TimestampedListBox
            app.TimestampedListBox = uilistbox(app.SetTimestampsPanel);
            app.TimestampedListBox.Items = {};
            app.TimestampedListBox.Multiselect = 'on';
            app.TimestampedListBox.Position = [320 6 213 142];
            app.TimestampedListBox.Value = {};

            % Create Label
            app.Label = uilabel(app.SetTimestampsPanel);
            app.Label.HorizontalAlignment = 'center';
            app.Label.Position = [224 56 10 22];
            app.Label.Text = ':';

            % Create Label_2
            app.Label_2 = uilabel(app.SetTimestampsPanel);
            app.Label_2.HorizontalAlignment = 'center';
            app.Label_2.Position = [270 89 10 22];
            app.Label_2.Text = ':';

            % Create Label_3
            app.Label_3 = uilabel(app.SetTimestampsPanel);
            app.Label_3.HorizontalAlignment = 'center';
            app.Label_3.Position = [224 89 10 22];
            app.Label_3.Text = ':';

            % Create Label_4
            app.Label_4 = uilabel(app.SetTimestampsPanel);
            app.Label_4.HorizontalAlignment = 'center';
            app.Label_4.Position = [270 56 10 22];
            app.Label_4.Text = ':';

            % Create StartLabel
            app.StartLabel = uilabel(app.SetTimestampsPanel);
            app.StartLabel.Position = [153 89 37 22];
            app.StartLabel.Text = 'Start';

            % Create StopLabel
            app.StopLabel = uilabel(app.SetTimestampsPanel);
            app.StopLabel.Position = [153 56 37 22];
            app.StopLabel.Text = 'Stop';

            % Create relTimeCheckBox
            app.relTimeCheckBox = uicheckbox(app.SetTimestampsPanel);
            app.relTimeCheckBox.Text = 'rel. Time';
            app.relTimeCheckBox.Position = [157 15 68 22];

            % Create DataManipulationandExtraFunctionsPanel
            app.DataManipulationandExtraFunctionsPanel = uipanel(app.GeneralTab);
            app.DataManipulationandExtraFunctionsPanel.Title = 'Data Manipulation and Extra Functions';
            app.DataManipulationandExtraFunctionsPanel.Position = [7 35 525 266];

            % Create ChooseDatasetstouseListBox
            app.ChooseDatasetstouseListBox = uilistbox(app.DataManipulationandExtraFunctionsPanel);
            app.ChooseDatasetstouseListBox.Items = {};
            app.ChooseDatasetstouseListBox.Multiselect = 'on';
            app.ChooseDatasetstouseListBox.Position = [6 124 250 92];
            app.ChooseDatasetstouseListBox.Value = {};

            % Create SearchEditField_3
            app.SearchEditField_3 = uieditfield(app.DataManipulationandExtraFunctionsPanel, 'text');
            app.SearchEditField_3.ValueChangingFcn = createCallbackFcn(app, @SearchEditFieldValueChanging, true);
            app.SearchEditField_3.Tag = 'search3';
            app.SearchEditField_3.Position = [56 98 200 22];

            % Create Filteringusingmedfilt1Panel
            app.Filteringusingmedfilt1Panel = uipanel(app.DataManipulationandExtraFunctionsPanel);
            app.Filteringusingmedfilt1Panel.Title = 'Filtering using medfilt1';
            app.Filteringusingmedfilt1Panel.Position = [7 3 249 90];

            % Create NeighborsSpinnerLabel
            app.NeighborsSpinnerLabel = uilabel(app.Filteringusingmedfilt1Panel);
            app.NeighborsSpinnerLabel.HorizontalAlignment = 'right';
            app.NeighborsSpinnerLabel.Position = [5 41 60 22];
            app.NeighborsSpinnerLabel.Text = 'Neighbors';

            % Create HelpButton
            app.HelpButton = uibutton(app.Filteringusingmedfilt1Panel, 'push');
            app.HelpButton.ButtonPushedFcn = createCallbackFcn(app, @HelpButtonPushed, true);
            app.HelpButton.FontSize = 8;
            app.HelpButton.FontWeight = 'bold';
            app.HelpButton.Position = [226 71 17 17];
            app.HelpButton.Text = '?';

            % Create NeighborsSpinner
            app.NeighborsSpinner = uispinner(app.Filteringusingmedfilt1Panel);
            app.NeighborsSpinner.Limits = [3 Inf];
            app.NeighborsSpinner.Position = [72 41 58 22];
            app.NeighborsSpinner.Value = 3;

            % Create DeviationEditField
            app.DeviationEditField = uieditfield(app.Filteringusingmedfilt1Panel, 'numeric');
            app.DeviationEditField.Position = [72 10 58 22];

            % Create DeviationEditFieldLabel
            app.DeviationEditFieldLabel = uilabel(app.Filteringusingmedfilt1Panel);
            app.DeviationEditFieldLabel.HorizontalAlignment = 'right';
            app.DeviationEditFieldLabel.Position = [6 10 55 22];
            app.DeviationEditFieldLabel.Text = 'Deviation';

            % Create VisualizeSwitchLabel
            app.VisualizeSwitchLabel = uilabel(app.Filteringusingmedfilt1Panel);
            app.VisualizeSwitchLabel.HorizontalAlignment = 'center';
            app.VisualizeSwitchLabel.FontSize = 10;
            app.VisualizeSwitchLabel.Position = [170 53 45 14];
            app.VisualizeSwitchLabel.Text = 'Visualize';

            % Create VisualizeSwitch
            app.VisualizeSwitch = uiswitch(app.Filteringusingmedfilt1Panel, 'slider');
            app.VisualizeSwitch.Position = [180 36 25 11];

            % Create FilterButton
            app.FilterButton = uibutton(app.Filteringusingmedfilt1Panel, 'push');
            app.FilterButton.ButtonPushedFcn = createCallbackFcn(app, @FilterButtonPushed, true);
            app.FilterButton.Position = [139 6 100 23];
            app.FilterButton.Text = 'Filter';

            % Create ClearButton_2
            app.ClearButton_2 = uibutton(app.DataManipulationandExtraFunctionsPanel, 'push');
            app.ClearButton_2.ButtonPushedFcn = createCallbackFcn(app, @ClearButton_2Pushed, true);
            app.ClearButton_2.FontColor = [1 0 0];
            app.ClearButton_2.Position = [330 220 48 23];
            app.ClearButton_2.Text = 'Clear';

            % Create AppendButton
            app.AppendButton = uibutton(app.DataManipulationandExtraFunctionsPanel, 'push');
            app.AppendButton.ButtonPushedFcn = createCallbackFcn(app, @AppendButtonPushed, true);
            app.AppendButton.Position = [385 219 63 23];
            app.AppendButton.Text = 'Append';

            % Create ChooseDatasetstouseListBoxLabel
            app.ChooseDatasetstouseListBoxLabel = uilabel(app.DataManipulationandExtraFunctionsPanel);
            app.ChooseDatasetstouseListBoxLabel.FontWeight = 'bold';
            app.ChooseDatasetstouseListBoxLabel.Position = [7 217 141 22];
            app.ChooseDatasetstouseListBoxLabel.Text = 'Choose Datasets to use';

            % Create ExportButton_2
            app.ExportButton_2 = uibutton(app.DataManipulationandExtraFunctionsPanel, 'push');
            app.ExportButton_2.ButtonPushedFcn = createCallbackFcn(app, @ExportButton_2Pushed, true);
            app.ExportButton_2.Position = [452 219 63 23];
            app.ExportButton_2.Text = 'Export';

            % Create CreatedListBoxLabel
            app.CreatedListBoxLabel = uilabel(app.DataManipulationandExtraFunctionsPanel);
            app.CreatedListBoxLabel.FontWeight = 'bold';
            app.CreatedListBoxLabel.Position = [268 220 50 22];
            app.CreatedListBoxLabel.Text = 'Created';

            % Create CreatedListBox
            app.CreatedListBox = uilistbox(app.DataManipulationandExtraFunctionsPanel);
            app.CreatedListBox.Items = {};
            app.CreatedListBox.Multiselect = 'on';
            app.CreatedListBox.Position = [267 124 250 92];
            app.CreatedListBox.Value = {};

            % Create CalcPowerButton
            app.CalcPowerButton = uibutton(app.DataManipulationandExtraFunctionsPanel, 'push');
            app.CalcPowerButton.Enable = 'off';
            app.CalcPowerButton.Position = [270 92 100 23];
            app.CalcPowerButton.Text = 'Calc Power';

            % Create GeoplotButton
            app.GeoplotButton = uibutton(app.DataManipulationandExtraFunctionsPanel, 'push');
            app.GeoplotButton.ButtonPushedFcn = createCallbackFcn(app, @GeoplotButtonPushed, true);
            app.GeoplotButton.Enable = 'off';
            app.GeoplotButton.Position = [394 93 115 23];
            app.GeoplotButton.Text = 'Geoplot';

            % Create GeoplotwithPowerButton
            app.GeoplotwithPowerButton = uibutton(app.DataManipulationandExtraFunctionsPanel, 'push');
            app.GeoplotwithPowerButton.Enable = 'off';
            app.GeoplotwithPowerButton.Position = [391 65 119 23];
            app.GeoplotwithPowerButton.Text = 'Geoplot with Power';

            % Create ExtFunctionsDropDown
            app.ExtFunctionsDropDown = uidropdown(app.DataManipulationandExtraFunctionsPanel);
            app.ExtFunctionsDropDown.Position = [369 34 141 22];

            % Create SearchEditField_3Label
            app.SearchEditField_3Label = uilabel(app.DataManipulationandExtraFunctionsPanel);
            app.SearchEditField_3Label.HorizontalAlignment = 'right';
            app.SearchEditField_3Label.Position = [7 98 43 22];
            app.SearchEditField_3Label.Text = 'Search';

            % Create ApplyFunctionButton
            app.ApplyFunctionButton = uibutton(app.DataManipulationandExtraFunctionsPanel, 'push');
            app.ApplyFunctionButton.ButtonPushedFcn = createCallbackFcn(app, @ApplyFunctionButtonPushed, true);
            app.ApplyFunctionButton.Position = [393 7 111 22];
            app.ApplyFunctionButton.Text = 'Apply Function';

            % Create ExtFunctionsDropDownLabel
            app.ExtFunctionsDropDownLabel = uilabel(app.DataManipulationandExtraFunctionsPanel);
            app.ExtFunctionsDropDownLabel.HorizontalAlignment = 'right';
            app.ExtFunctionsDropDownLabel.Position = [284 34 78 22];
            app.ExtFunctionsDropDownLabel.Text = 'Ext. Functions';

            % Create PlotSettingsPanel
            app.PlotSettingsPanel = uipanel(app.GeneralTab);
            app.PlotSettingsPanel.Title = 'Plot Settings';
            app.PlotSettingsPanel.Position = [541 35 540 266];

            % Create RowsLabel
            app.RowsLabel = uilabel(app.PlotSettingsPanel);
            app.RowsLabel.HorizontalAlignment = 'right';
            app.RowsLabel.Position = [130 213 35 22];
            app.RowsLabel.Text = 'Rows';

            % Create ColumnsEditField
            app.ColumnsEditField = uieditfield(app.PlotSettingsPanel, 'numeric');
            app.ColumnsEditField.Limits = [1 9];
            app.ColumnsEditField.ValueChangedFcn = createCallbackFcn(app, @NumSP, true);
            app.ColumnsEditField.Position = [76 213 45 22];
            app.ColumnsEditField.Value = 1;

            % Create RowsEditField
            app.RowsEditField = uieditfield(app.PlotSettingsPanel, 'numeric');
            app.RowsEditField.Limits = [1 9];
            app.RowsEditField.ValueChangedFcn = createCallbackFcn(app, @NumSP, true);
            app.RowsEditField.Position = [189 213 43 22];
            app.RowsEditField.Value = 1;

            % Create FigureTitleCheckBox
            app.FigureTitleCheckBox = uicheckbox(app.PlotSettingsPanel);
            app.FigureTitleCheckBox.ValueChangedFcn = createCallbackFcn(app, @FigureTitleCheckBoxValueChanged, true);
            app.FigureTitleCheckBox.Text = '';
            app.FigureTitleCheckBox.Position = [31 182 16 22];

            % Create ColumnsLabel
            app.ColumnsLabel = uilabel(app.PlotSettingsPanel);
            app.ColumnsLabel.HorizontalAlignment = 'right';
            app.ColumnsLabel.Position = [6 213 52 22];
            app.ColumnsLabel.Text = 'Columns';

            % Create TitleLabel
            app.TitleLabel = uilabel(app.PlotSettingsPanel);
            app.TitleLabel.HorizontalAlignment = 'right';
            app.TitleLabel.Enable = 'off';
            app.TitleLabel.Position = [47 182 27 22];
            app.TitleLabel.Text = 'Title';

            % Create OverallTitleField
            app.OverallTitleField = uieditfield(app.PlotSettingsPanel, 'text');
            app.OverallTitleField.Enable = 'off';
            app.OverallTitleField.Position = [88 182 144 22];

            % Create SubplotTitleEditFieldLabel
            app.SubplotTitleEditFieldLabel = uilabel(app.PlotSettingsPanel);
            app.SubplotTitleEditFieldLabel.HorizontalAlignment = 'right';
            app.SubplotTitleEditFieldLabel.Position = [3 154 71 22];
            app.SubplotTitleEditFieldLabel.Text = 'Subplot Title';

            % Create SubplotTitle
            app.SubplotTitle = uieditfield(app.PlotSettingsPanel, 'text');
            app.SubplotTitle.Position = [88 154 144 22];

            % Create xAxisDropDown
            app.xAxisDropDown = uidropdown(app.PlotSettingsPanel);
            app.xAxisDropDown.Items = {'Time [h:m:s + Date]', 'Time [h:m:s]', 'Time [s]', 'Distance [m]', 'Custom'};
            app.xAxisDropDown.Position = [88 122 144 22];
            app.xAxisDropDown.Value = 'Time [h:m:s + Date]';

            % Create yAxisLabel
            app.yAxisLabel = uilabel(app.PlotSettingsPanel);
            app.yAxisLabel.HorizontalAlignment = 'right';
            app.yAxisLabel.Position = [36 92 38 22];
            app.yAxisLabel.Text = 'y-Axis';

            % Create yAxisTitle
            app.yAxisTitle = uieditfield(app.PlotSettingsPanel, 'text');
            app.yAxisTitle.Position = [88 92 144 22];

            % Create GridonCheckBox
            app.GridonCheckBox = uicheckbox(app.PlotSettingsPanel);
            app.GridonCheckBox.Text = 'Grid on';
            app.GridonCheckBox.Position = [11 60 61 22];

            % Create LegendonCheckBox
            app.LegendonCheckBox = uicheckbox(app.PlotSettingsPanel);
            app.LegendonCheckBox.Text = 'Legend on';
            app.LegendonCheckBox.Position = [88 60 79 22];

            % Create FeaturesPanel
            app.FeaturesPanel = uipanel(app.PlotSettingsPanel);
            app.FeaturesPanel.Title = 'Features';
            app.FeaturesPanel.Position = [260 65 258 177];

            % Create Panel_3
            app.Panel_3 = uipanel(app.FeaturesPanel);
            app.Panel_3.Position = [10 95 234 59];

            % Create LowerEditFieldLabel
            app.LowerEditFieldLabel = uilabel(app.Panel_3);
            app.LowerEditFieldLabel.HorizontalAlignment = 'right';
            app.LowerEditFieldLabel.Position = [121 30 38 22];
            app.LowerEditFieldLabel.Text = 'Lower';

            % Create SetLimitsCheckBox
            app.SetLimitsCheckBox = uicheckbox(app.Panel_3);
            app.SetLimitsCheckBox.Text = 'Set Limits';
            app.SetLimitsCheckBox.Position = [18 19 75 22];

            % Create LowerEditField
            app.LowerEditField = uieditfield(app.Panel_3, 'numeric');
            app.LowerEditField.Position = [174 30 53 22];

            % Create UpperEditFieldLabel
            app.UpperEditFieldLabel = uilabel(app.Panel_3);
            app.UpperEditFieldLabel.HorizontalAlignment = 'right';
            app.UpperEditFieldLabel.Position = [121 3 38 22];
            app.UpperEditFieldLabel.Text = 'Upper';

            % Create UpperEditField
            app.UpperEditField = uieditfield(app.Panel_3, 'numeric');
            app.UpperEditField.Position = [174 3 53 22];

            % Create CustomxAxisDropDown
            app.CustomxAxisDropDown = uidropdown(app.FeaturesPanel);
            app.CustomxAxisDropDown.Items = {};
            app.CustomxAxisDropDown.Position = [86 67 166 22];
            app.CustomxAxisDropDown.Value = {};

            % Create xAxisTitle
            app.xAxisTitle = uieditfield(app.FeaturesPanel, 'text');
            app.xAxisTitle.Position = [74 35 178 22];

            % Create yAxisTitleLabel
            app.yAxisTitleLabel = uilabel(app.FeaturesPanel);
            app.yAxisTitleLabel.HorizontalAlignment = 'right';
            app.yAxisTitleLabel.Position = [11 5 61 22];
            app.yAxisTitleLabel.Text = '2nd y-Axis ';

            % Create yAxisTitle_2
            app.yAxisTitle_2 = uieditfield(app.FeaturesPanel, 'text');
            app.yAxisTitle_2.Position = [74 5 178 22];

            % Create CustomxAxisLabel
            app.CustomxAxisLabel = uilabel(app.FeaturesPanel);
            app.CustomxAxisLabel.HorizontalAlignment = 'right';
            app.CustomxAxisLabel.Position = [-1 67 82 22];
            app.CustomxAxisLabel.Text = 'Custom x-Axis';

            % Create yAxisTitleLabel_2
            app.yAxisTitleLabel_2 = uilabel(app.FeaturesPanel);
            app.yAxisTitleLabel_2.HorizontalAlignment = 'right';
            app.yAxisTitleLabel_2.Position = [10 35 61 22];
            app.yAxisTitleLabel_2.Text = 'x-Axis ';

            % Create Panel_2
            app.Panel_2 = uipanel(app.PlotSettingsPanel);
            app.Panel_2.Position = [6 7 238 42];

            % Create Field_SelectedSP
            app.Field_SelectedSP = uieditfield(app.Panel_2, 'numeric');
            app.Field_SelectedSP.Limits = [1 81];
            app.Field_SelectedSP.HorizontalAlignment = 'center';
            app.Field_SelectedSP.FontSize = 18;
            app.Field_SelectedSP.Position = [149 9 30 24];
            app.Field_SelectedSP.Value = 1;

            % Create textfield
            app.textfield = uieditfield(app.Panel_2, 'text');
            app.textfield.Editable = 'off';
            app.textfield.Enable = 'off';
            app.textfield.Position = [184 10 13 22];
            app.textfield.Value = '/';

            % Create Field_NoSP
            app.Field_NoSP = uieditfield(app.Panel_2, 'numeric');
            app.Field_NoSP.Editable = 'off';
            app.Field_NoSP.HorizontalAlignment = 'center';
            app.Field_NoSP.FontSize = 18;
            app.Field_NoSP.Position = [201 9 30 24];
            app.Field_NoSP.Value = 1;

            % Create SelectedSubplotEditFieldLabel
            app.SelectedSubplotEditFieldLabel = uilabel(app.Panel_2);
            app.SelectedSubplotEditFieldLabel.HorizontalAlignment = 'right';
            app.SelectedSubplotEditFieldLabel.FontSize = 18;
            app.SelectedSubplotEditFieldLabel.Position = [5 3 141 36];
            app.SelectedSubplotEditFieldLabel.Text = 'Selected Subplot';

            % Create ButtonGroup
            app.ButtonGroup = uibuttongroup(app.PlotSettingsPanel);
            app.ButtonGroup.Position = [250 3 128 49];

            % Create button_stint
            app.button_stint = uitogglebutton(app.ButtonGroup);
            app.button_stint.Text = 'Entire Stint';
            app.button_stint.Position = [10 23 109 23];
            app.button_stint.Value = true;

            % Create button_timestamped
            app.button_timestamped = uitogglebutton(app.ButtonGroup);
            app.button_timestamped.Text = 'Timestamped';
            app.button_timestamped.Position = [15 1 100 23];

            % Create PlotSubplotButton
            app.PlotSubplotButton = uibutton(app.PlotSettingsPanel, 'push');
            app.PlotSubplotButton.ButtonPushedFcn = createCallbackFcn(app, @PlotSubplotButtonPushed, true);
            app.PlotSubplotButton.FontSize = 18;
            app.PlotSubplotButton.FontWeight = 'bold';
            app.PlotSubplotButton.Position = [395 28 121 28];
            app.PlotSubplotButton.Text = 'Plot Subplot';

            % Create ResetSubplotButton
            app.ResetSubplotButton = uibutton(app.PlotSettingsPanel, 'push');
            app.ResetSubplotButton.ButtonPushedFcn = createCallbackFcn(app, @ResetSubplotButtonPushed, true);
            app.ResetSubplotButton.Position = [411 2 84 23];
            app.ResetSubplotButton.Text = 'Reset Subplot';

            % Create xAxisDropDownLabel
            app.xAxisDropDownLabel = uilabel(app.PlotSettingsPanel);
            app.xAxisDropDownLabel.HorizontalAlignment = 'right';
            app.xAxisDropDownLabel.Position = [6 122 68 22];
            app.xAxisDropDownLabel.Text = 'x-Axis';

            % Create ndyAxisCheckBox
            app.ndyAxisCheckBox = uicheckbox(app.PlotSettingsPanel);
            app.ndyAxisCheckBox.Text = '2nd y-Axis';
            app.ndyAxisCheckBox.Position = [176 60 78 22];

            % Create PresetsTab
            app.PresetsTab = uitab(app.TabGroup);
            app.PresetsTab.Title = 'Presets';

            % Create PlotPanel
            app.PlotPanel = uipanel(app.PresetsTab);
            app.PlotPanel.Title = 'Plot';
            app.PlotPanel.Position = [210 35 733 441];

            % Create savename
            app.savename = uieditfield(app.PresetsTab, 'text');
            app.savename.Position = [737 5 161 22];
            app.savename.Value = 'plot1';

            % Create Format
            app.Format = uidropdown(app.PresetsTab);
            app.Format.Items = {'png', 'pdf', 'fig', 'm'};
            app.Format.Position = [905 4 65 22];
            app.Format.Value = 'png';

            % Create SaveButton
            app.SaveButton = uibutton(app.PresetsTab, 'push');
            app.SaveButton.ButtonPushedFcn = createCallbackFcn(app, @SaveButtonPushed, true);
            app.SaveButton.Position = [974 4 100 23];
            app.SaveButton.Text = 'Save';

            % Create SetTimestampsPanel_2
            app.SetTimestampsPanel_2 = uipanel(app.PresetsTab);
            app.SetTimestampsPanel_2.Title = 'Set Timestamps';
            app.SetTimestampsPanel_2.Position = [7 35 196 441];

            % Create LapsiffoundListBoxLabel_2
            app.LapsiffoundListBoxLabel_2 = uilabel(app.SetTimestampsPanel_2);
            app.LapsiffoundListBoxLabel_2.Position = [12 391 82 22];
            app.LapsiffoundListBoxLabel_2.Text = 'Laps (if found)';

            % Create Laps_2
            app.Laps_2 = uilistbox(app.SetTimestampsPanel_2);
            app.Laps_2.Items = {};
            app.Laps_2.Position = [10 191 177 198];
            app.Laps_2.Value = {};

            % Create UseCustomTimestampsCheckBox_2
            app.UseCustomTimestampsCheckBox_2 = uicheckbox(app.SetTimestampsPanel_2);
            app.UseCustomTimestampsCheckBox_2.Text = 'Use Custom Timestamps';
            app.UseCustomTimestampsCheckBox_2.Position = [30 164 156 22];

            % Create DateDropDown_2
            app.DateDropDown_2 = uidropdown(app.SetTimestampsPanel_2);
            app.DateDropDown_2.Items = {};
            app.DateDropDown_2.Position = [48 137 138 22];
            app.DateDropDown_2.Value = {};

            % Create DateDropDown_2Label
            app.DateDropDown_2Label = uilabel(app.SetTimestampsPanel_2);
            app.DateDropDown_2Label.Position = [15 137 30 22];
            app.DateDropDown_2Label.Text = 'Date';

            % Create start_h_2
            app.start_h_2 = uieditfield(app.SetTimestampsPanel_2, 'numeric');
            app.start_h_2.Limits = [0 23];
            app.start_h_2.ValueDisplayFormat = '%02.0f';
            app.start_h_2.Position = [53 106 30 22];

            % Create start_m_2
            app.start_m_2 = uieditfield(app.SetTimestampsPanel_2, 'numeric');
            app.start_m_2.Limits = [0 59];
            app.start_m_2.ValueDisplayFormat = '%02.0f';
            app.start_m_2.HorizontalAlignment = 'center';
            app.start_m_2.Position = [101 106 30 22];

            % Create start_s_2
            app.start_s_2 = uieditfield(app.SetTimestampsPanel_2, 'numeric');
            app.start_s_2.Limits = [0 59];
            app.start_s_2.ValueDisplayFormat = '%02.0f';
            app.start_s_2.Position = [146 106 32 22];

            % Create end_h_2
            app.end_h_2 = uieditfield(app.SetTimestampsPanel_2, 'numeric');
            app.end_h_2.Limits = [0 23];
            app.end_h_2.ValueDisplayFormat = '%02.0f';
            app.end_h_2.HorizontalAlignment = 'center';
            app.end_h_2.Position = [53 73 30 22];

            % Create end_m_2
            app.end_m_2 = uieditfield(app.SetTimestampsPanel_2, 'numeric');
            app.end_m_2.Limits = [0 59];
            app.end_m_2.ValueDisplayFormat = '%02.0f';
            app.end_m_2.HorizontalAlignment = 'center';
            app.end_m_2.Position = [101 73 30 22];

            % Create end_s_2
            app.end_s_2 = uieditfield(app.SetTimestampsPanel_2, 'numeric');
            app.end_s_2.Limits = [0 59];
            app.end_s_2.ValueDisplayFormat = '%02.0f';
            app.end_s_2.HorizontalAlignment = 'center';
            app.end_s_2.Position = [146 73 32 22];

            % Create Label_5
            app.Label_5 = uilabel(app.SetTimestampsPanel_2);
            app.Label_5.HorizontalAlignment = 'center';
            app.Label_5.Position = [87 73 10 22];
            app.Label_5.Text = ':';

            % Create Label_6
            app.Label_6 = uilabel(app.SetTimestampsPanel_2);
            app.Label_6.HorizontalAlignment = 'center';
            app.Label_6.Position = [133 106 10 22];
            app.Label_6.Text = ':';

            % Create Label_7
            app.Label_7 = uilabel(app.SetTimestampsPanel_2);
            app.Label_7.HorizontalAlignment = 'center';
            app.Label_7.Position = [87 106 10 22];
            app.Label_7.Text = ':';

            % Create Label_8
            app.Label_8 = uilabel(app.SetTimestampsPanel_2);
            app.Label_8.HorizontalAlignment = 'center';
            app.Label_8.Position = [133 73 10 22];
            app.Label_8.Text = ':';

            % Create StartLabel_2
            app.StartLabel_2 = uilabel(app.SetTimestampsPanel_2);
            app.StartLabel_2.Position = [16 106 37 22];
            app.StartLabel_2.Text = 'Start';

            % Create StopLabel_2
            app.StopLabel_2 = uilabel(app.SetTimestampsPanel_2);
            app.StopLabel_2.Position = [16 73 37 22];
            app.StopLabel_2.Text = 'Stop';

            % Create xAxisDropDown_2
            app.xAxisDropDown_2 = uidropdown(app.SetTimestampsPanel_2);
            app.xAxisDropDown_2.Items = {'Time [h:m:s+Date]', 'Time [h:m:s]', 'Time [s]', 'Distance [m]', 'Custom'};
            app.xAxisDropDown_2.Position = [48 43 138 22];
            app.xAxisDropDown_2.Value = 'Time [h:m:s+Date]';

            % Create xAxisDropDown_2Label
            app.xAxisDropDown_2Label = uilabel(app.SetTimestampsPanel_2);
            app.xAxisDropDown_2Label.HorizontalAlignment = 'right';
            app.xAxisDropDown_2Label.Position = [4 43 37 22];
            app.xAxisDropDown_2Label.Text = 'x-Axis';

            % Create PlotPresetsButton
            app.PlotPresetsButton = uibutton(app.PresetsTab, 'push');
            app.PlotPresetsButton.ButtonPushedFcn = createCallbackFcn(app, @PlotPresetsButtonPushed, true);
            app.PlotPresetsButton.Position = [974 488 101 23];
            app.PlotPresetsButton.Text = 'Plot Presets';

            % Create ButtonGroup_2
            app.ButtonGroup_2 = uibuttongroup(app.PresetsTab);
            app.ButtonGroup_2.Position = [685 483 170 30];

            % Create button_stint_2
            app.button_stint_2 = uitogglebutton(app.ButtonGroup_2);
            app.button_stint_2.Text = 'Entire Stint';
            app.button_stint_2.Position = [3 4 73 23];
            app.button_stint_2.Value = true;

            % Create button_timestamped_2
            app.button_timestamped_2 = uitogglebutton(app.ButtonGroup_2);
            app.button_timestamped_2.Text = 'Timestamped';
            app.button_timestamped_2.Position = [82 4 83 23];

            % Create PlotsDropDown
            app.PlotsDropDown = uidropdown(app.PresetsTab);
            app.PlotsDropDown.Items = {'Driver - General', 'Driver - Steering', 'Driver - Braking', 'Driver - Statistics', 'Powertrain', 'Brakes', 'Accumulator', 'Inverter', 'Suspension - Positions', 'Suspension - Velocities', 'Suspension - Histogram', 'Tires - Temperatures', 'Tires - Friction Circle', 'Custom'};
            app.PlotsDropDown.Position = [412 488 259 22];
            app.PlotsDropDown.Value = 'Driver - General';

            % Create PlottypeLabel
            app.PlottypeLabel = uilabel(app.PresetsTab);
            app.PlottypeLabel.HorizontalAlignment = 'right';
            app.PlottypeLabel.Position = [368 488 32 22];
            app.PlottypeLabel.Text = 'Plots';

            % Create QuickStatsTextAreaLabel
            app.QuickStatsTextAreaLabel = uilabel(app.PresetsTab);
            app.QuickStatsTextAreaLabel.HorizontalAlignment = 'right';
            app.QuickStatsTextAreaLabel.Position = [953 456 66 22];
            app.QuickStatsTextAreaLabel.Text = 'Quick Stats';

            % Create QuickStatsTextArea
            app.QuickStatsTextArea = uitextarea(app.PresetsTab);
            app.QuickStatsTextArea.Position = [953 36 129 419];

            % Create LoadPresetsButton
            app.LoadPresetsButton = uibutton(app.PresetsTab, 'push');
            app.LoadPresetsButton.ButtonPushedFcn = createCallbackFcn(app, @LoadPresetsButtonPushed, true);
            app.LoadPresetsButton.Position = [7 487 119 23];
            app.LoadPresetsButton.Text = 'Load (Presets)';

            % Create Preset
            app.Preset = uidropdown(app.PresetsTab);
            app.Preset.Items = {};
            app.Preset.ValueChangedFcn = createCallbackFcn(app, @PresetValueChanged, true);
            app.Preset.Position = [137 487 81 23];
            app.Preset.Value = {};

            % Create ApplySeasonButton
            app.ApplySeasonButton = uibutton(app.PresetsTab, 'push');
            app.ApplySeasonButton.ButtonPushedFcn = createCallbackFcn(app, @ApplySeasonButtonPushed, true);
            app.ApplySeasonButton.Position = [231 487 116 23];
            app.ApplySeasonButton.Text = 'Apply Season';

            % Create EditField_2
            app.EditField_2 = uieditfield(app.PresetsTab, 'text');
            app.EditField_2.Position = [861 487 100 22];

            % Create ContextMenu
            app.ContextMenu = uicontextmenu(app.UIFigure);

            % Create CopyMenu
            app.CopyMenu = uimenu(app.ContextMenu);
            app.CopyMenu.MenuSelectedFcn = createCallbackFcn(app, @CopyMenuSelected, true);
            app.CopyMenu.Text = 'Copy';
            
            % Assign app.ContextMenu
            app.AvailableDatasetsListBox.ContextMenu = app.ContextMenu;

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

            % 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