classdef PAG_GUI < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                        matlab.ui.Figure
        TabGroup                        matlab.ui.container.TabGroup
        EBSDmapsTab                     matlab.ui.container.Tab
        EBSDVariableNameEditFieldLabel  matlab.ui.control.Label
        EBSDVariableNameEditField       matlab.ui.control.EditField
        MartensiteListBoxLabel          matlab.ui.control.Label
        MartensiteListBox               matlab.ui.control.ListBox
        GetPhaseListButton              matlab.ui.control.Button
        SelectPhasesText                matlab.ui.control.Label
        AusteniteListBoxLabel           matlab.ui.control.Label
        AusteniteListBox                matlab.ui.control.ListBox
        CurrentlyselectedphasesLabel    matlab.ui.control.Label
        MartensiteLabel                 matlab.ui.control.Label
        AusteniteLabel                  matlab.ui.control.Label
        SelecttoaddaustenitetophaselistCheckBox  matlab.ui.control.CheckBox
        Rev1Label                       matlab.ui.control.Label
        PAGsviaMCLTab                   matlab.ui.container.Tab
        OrientationrelationshipdeterminationPanel  matlab.ui.container.Panel
        DetermineORButton               matlab.ui.control.Button
        PlotresultButton                matlab.ui.control.Button
        viewdevelopmentCheckBox         matlab.ui.control.CheckBox
        SaveORtoworkspaceButton         matlab.ui.control.Button
        SaveFcc2bccCheckBox             matlab.ui.control.CheckBox
        SaveVariantsHistCheckBox        matlab.ui.control.CheckBox
        WhiteonblackCheckBox            matlab.ui.control.CheckBox
        ORDropDown                      matlab.ui.control.DropDown
        PlotIteORButton                 matlab.ui.control.Button
        ItezoomedPFCheckBox             matlab.ui.control.CheckBox
        ItePFtrueCheckBox               matlab.ui.control.CheckBox
        ConstructundirectedgraphandcallMCLPanel  matlab.ui.container.Panel
        CallMCLButton                   matlab.ui.control.Button
        InflationpowerEditFieldLabel    matlab.ui.control.Label
        InflationpowerEditField         matlab.ui.control.NumericEditField
        MCLLabel                        matlab.ui.control.Label
        SavetoworkspaceButton_4         matlab.ui.control.Button
        ExplainSaveLabel_2              matlab.ui.control.Label
        ReconstructparentaustenitePanel  matlab.ui.container.Panel
        ReconstructButton               matlab.ui.control.Button
        PlotresultsButton               matlab.ui.control.Button
        SavetoworkspaceButton           matlab.ui.control.Button
        ExplainSaveLabel                matlab.ui.control.Label
        GrainsdatasourceButtonGroup     matlab.ui.container.ButtonGroup
        ImportGrainDataButton           matlab.ui.control.RadioButton
        GeneratenewgrainsButton         matlab.ui.control.RadioButton
        ORLabel                         matlab.ui.control.Label
        DegreeBoundaryEditFieldLabel    matlab.ui.control.Label
        DegreeBoundaryEditField         matlab.ui.control.NumericEditField
        GrainsvariableNameEditFieldLabel  matlab.ui.control.Label
        GrainsvariableNameEditField     matlab.ui.control.EditField
        savegrainstoworkspaceandupdateCheckBox  matlab.ui.control.CheckBox
        EbsdVarName                     matlab.ui.control.EditField
        ImportOrRunButton               matlab.ui.control.Button
        GrainsAmountLabel               matlab.ui.control.Label
        CleanUpCheckBox                 matlab.ui.control.CheckBox
        CleanUpEditField                matlab.ui.control.NumericEditField
        pixelsLabel                     matlab.ui.control.Label
        Rev1Label_2                     matlab.ui.control.Label
        MCLAnalysisTab                  matlab.ui.container.Tab
        Rev1Label_3                     matlab.ui.control.Label
        ResolutionVariantsPanel         matlab.ui.container.Panel
        CalculateVarsButton             matlab.ui.control.Button
        PlotvariantsButton              matlab.ui.control.Button
        PlotORButton_4                  matlab.ui.control.Button
        PFtrueCheckBox                  matlab.ui.control.CheckBox
        zoomedPFCheckBox                matlab.ui.control.CheckBox
        SavetoworkspaceButton_2         matlab.ui.control.Button
        savevariantstrueCheckBox        matlab.ui.control.CheckBox
        saveORtrueCheckBox              matlab.ui.control.CheckBox
        ResolutionVariantsPanel_3       matlab.ui.container.Panel
        PlotgrainbygrainButton          matlab.ui.control.Button
        recevaluationLabel              matlab.ui.control.Label
        SavetoworkspaceButton_3         matlab.ui.control.Button
        graindeviationvaluesasdevisLabel  matlab.ui.control.Label
        PAGSviatriplepointsTab          matlab.ui.container.Tab
        OrientationrelationshipdeterminationPanel_2  matlab.ui.container.Panel
        TriplepointORButton             matlab.ui.control.Button
        TriplepointdevelopmentCheckBox  matlab.ui.control.CheckBox
        AusMisoPairsButton              matlab.ui.control.Button
        PlottingandsavingPanel          matlab.ui.container.Panel
        AusTriplePointSave              matlab.ui.control.Button
        TriplepointSaveFcc2bccCheckBox  matlab.ui.control.CheckBox
        TriplepointSaveVariantsHistCheckBox  matlab.ui.control.CheckBox
        ExplainSaveLabel_4              matlab.ui.control.Label
        TriplepointSaveFcc2bccCheckBox_2  matlab.ui.control.CheckBox
        TriplepointSaveFcc2bccCheckBox_3  matlab.ui.control.CheckBox
        TriplePointPlotButton           matlab.ui.control.Button
        PlottingoptionsButtonGroup      matlab.ui.container.ButtonGroup
        BandcontrastonlyButton          matlab.ui.control.RadioButton
        AusteniteindividualmisorientationpairsButton  matlab.ui.control.RadioButton
        AustenitetriplepointsButton     matlab.ui.control.RadioButton
        BoundaryoptionsButtonGroup      matlab.ui.container.ButtonGroup
        BlocksButton                    matlab.ui.control.RadioButton
        PacketsButton                   matlab.ui.control.RadioButton
        PAGSButton                      matlab.ui.control.RadioButton
        NoBandContrastCheckBox          matlab.ui.control.CheckBox
    end

    %Parent austenite reconstruction with MCL clustering, graphical user interface. Tuomo Nyyssönen 2018.
    %Many thanks to Dr. Jessica Hiscocks for the GUI template and the grain and ebsd import functions.
    %rev 0
    
    properties (Access = private)
        TempEbsdData % Stores ebsd data for plotting and grain calculations
        EbsdPhaseWds %list of valid phases to populate list boxes on tab 1
        EbsdPhaseNum %index of all phases containing ebsd indexed data.  Min value 1 (no 'not indexed' 'all indexed' entries)
        ImportedEbsdVarName %save name of ebsd variable for potential updating after grains later
        TempGrainsData % Store grains and boundary data for plotting and annotation
        Symmetries % Contains the crystal symmetries necessary for reconstruction and OR determination
        MCL % Contains the data necessary for MCL clustering
        Clusters % Contains the sparse matrix of discrete clusters submitted by MCL
        ib % Sparse matrix converted to line entries, each line contains grains of the corresponding cluster
        orbounds % Boundaries for blocks, packets and PAGs determined with the iterative algorithm
        fcc2bcc % the austenite-martensite orientation relationship determined with the iterative algorithm
        TempEbsdAusData % Stores the reconstructed ebsd data
        TempGrainsAusData % Stores the reconstructed grain data
        HistVariants % Variant boundary histogram between V1 and V1-V24, determined with the iterative algorithm
        devis % The deviation angle between the austenite orientation of a single grain versus that of the cluster
        symrots % The symmetry operators arranged to produce an easily understood block-packet boundary indexation
        variants % The V1-V24 variant index for each orientation pixel
        odf_aus % Stores the odfs necessary for visualization of the orientation relationships
        fcc2bcc_rec % The orientation relationship recalculated on a point-by-point basis
        bcc2fcc_odf % ODF of the iteratively determined OR for visualization purposes
        fcc2bcc_triple % fcc2bcc OR determined directly from boundaries
        bcc2fcc_odf_triple % Description
        TempEbsdAus_Pairs % Description
        TempEbsdAus_Triple %
        V_rec % Description
        F_rec % Description
        TripleVariants % Description
    end
    

    methods (Access = private)

        % Button pushed function: GetPhaseListButton
        function GetPhaseListButtonPushed(app, event)
            %Try to import from main workspace
            try
                app.TempEbsdData = evalin('base', app.EBSDVariableNameEditField.Value);
                %save the variable name for later use with grain calcs
                app.ImportedEbsdVarName=app.EBSDVariableNameEditField.Value;
                %if it works, update the phase list
                %get list of unique phases (don't use mineralList- can be listed but have no data)
                %if in .phase, must have some indexed data
                app.EbsdPhaseNum=app.TempEbsdData.phaseMap(2:end);
                %convert values to list of options in words
                app.EbsdPhaseWds=app.TempEbsdData.mineralList(2:end);
                
                %Populate martensite selection box:
                app.MartensiteListBox.Items=app.TempEbsdData.mineralList(2:end);
                %Give the list box items a numerical value:
                app.MartensiteListBox.ItemsData=1:length(app.MartensiteListBox.Items);
                %Make the last item selection default:
                app.MartensiteListBox.Value= length(app.MartensiteListBox.Items);
                %Assign the last item as the martensite symmetry for OR analysis:
                app.Symmetries{1} = app.TempEbsdData.CSList{app.MartensiteListBox.Value+1};
                app.MartensiteLabel.Text = ['Martensite: ' app.Symmetries{1}.mineral];
                
                %Populate austenite selection box:
                app.AusteniteListBox.Items=app.TempEbsdData.mineralList(2:end);
                %Give the list box items a numerical value:
                app.AusteniteListBox.ItemsData=1:length(app.MartensiteListBox.Items);
                %Make the last item selection default:
                app.AusteniteListBox.Value= length(app.AusteniteListBox.Items);
                %Assign the last item as the martensite symmetry for OR analysis:
                app.Symmetries{2} = app.TempEbsdData.CSList{app.AusteniteListBox.Value+1};
                app.AusteniteLabel.Text = ['Austenite: ' app.Symmetries{2}.mineral];
                
                %Indicate succesful data import:
                app.GetPhaseListButton.BackgroundColor='green';
                app.GetPhaseListButton.Text='EBSD data loaded';
                
                %Enable OR determination via triple points:
                app.TriplepointORButton.Enable = 'on';
                app.TriplepointdevelopmentCheckBox.Enable = 'on';
                
            catch
                msg = 'No variable by that name in workspace.  Import to main workspace using import_wizard(''EBSD'') command first';
                errordlg(msg)
                return
            end
        end

        % Value changed function: MartensiteListBox
        function MartensiteListBoxValueChanged(app, event)
            value = app.MartensiteListBox.Value;
            %Determine selection as the martensite symmetry:
            app.Symmetries{1} = app.TempEbsdData.CSList{value + 1};
            %Update label to indicate choice:
            app.MartensiteLabel.Text = ['Martensite: ' app.Symmetries{1}.mineral];
        end

        % Value changed function: AusteniteListBox
        function AusteniteListBoxValueChanged(app, event)
            value = app.AusteniteListBox.Value;
            %Determine selection as the martensite symmetry:
            app.Symmetries{2} = app.TempEbsdData.CSList{value + 1};
            %Update label to indicate choice:
            app.AusteniteLabel.Text = ['Austenite: ' app.Symmetries{2}.mineral];
        end

        % Button pushed function: DetermineORButton
        function DetermineORButtonPushed(app, event)
            %Indicate progress:
            app.DetermineORButton.BackgroundColor='yellow';
            app.DetermineORButton.Text='working...';
            %Call the or determination function:
            [app.fcc2bcc,app.MCL{1},app.MCL{2},app.orbounds{1},app.orbounds{2},app.orbounds{3},app.orbounds{4},app.HistVariants,app.symrots,app.bcc2fcc_odf] = determineor(app.Symmetries,app.TempGrainsData,app.viewdevelopmentCheckBox.Value);
            
            %Determine the orientation relationship ODF strictly for visualization:
            
            %Show finished:
            app.DetermineORButton.BackgroundColor='green';
            app.DetermineORButton.Text='OR determined';
            %Enable the next work and analysis phase:
            app.CallMCLButton.Enable = 'on';
            app.InflationpowerEditField.Enable = 'on';
            app.PlotresultButton.Enable = 'on';
            app.SaveFcc2bccCheckBox.Enable = 'on';
            app.SaveVariantsHistCheckBox.Enable = 'on';
            app.ORDropDown.Enable = 'on';
            app.SaveORtoworkspaceButton.Enable = 'on';
            app.WhiteonblackCheckBox.Enable = 'on';
            app.PlotIteORButton.Enable = 'on';
            app.ItezoomedPFCheckBox.Enable = 'on';
            app.ItePFtrueCheckBox.Enable = 'on';
            
        end

        % Button pushed function: CallMCLButton
        function CallMCLButtonPushed(app, event)
            %Indicate progress:
            app.CallMCLButton.BackgroundColor='yellow';
            app.CallMCLButton.Text='working...';
            %Use the Burr survival algorithm to determine 0-1 similarity between each grain pair (based on misorientation angle):
            surv_val = 1-cdf('Burr',app.MCL{1},2,5,1);
            %Prune surv_val below certain value
            surv_val(surv_val<0.001) = 0;
            %Construct the sparse undirected graph required by MCL:
            mcl = [app.MCL{2}, surv_val];
            z = sparse(mcl(:,1),mcl(:,2),mcl(:,3));
            zz = z;
            zzz = [zz;zeros((length(zz) - min(size(zz))),length(zz))];
            zzz = zzz' + zzz;
            zzzz = zzz + speye(length(zzz));
            zzzzzz = sparse(zzzz);
            %Call MCL:
            app.Clusters = full(mcl_func(app.InflationpowerEditField.Value,zzzzzz));
            %Show finished:
            app.CallMCLButton.BackgroundColor='green';
            app.CallMCLButton.Text='MCL complete';
            %Change MCL output to row-by-row grain lists (each row is one cluster):
            [row_mcl,col_mcl] = find(app.Clusters);
            [a,b] = ismember(row_mcl,1:length(app.TempGrainsData));
            idx = col_mcl;
            app.ib = accumarray(nonzeros(b), idx(a), [], @(x){x});
            %Find empty cells
            emptyCells = cellfun(@isempty,app.ib);
            %Remove empty cells
            app.ib(emptyCells) = [];
            %Update label for determining succesful clustering:
            app.MCLLabel.Text = ['MCL found ' num2str(length(app.ib)) ' discrete clusters.'];
            %Enable next work phase:
            app.ReconstructButton.Enable = 'on';
            app.SavetoworkspaceButton_4.Enable = 'on';
            app.ExplainSaveLabel_2.Enable = 'on';
        end

        % Button pushed function: ImportOrRunButton
        function ImportOrRunButtonPushed(app, event)
            if app.ImportGrainDataButton.Value==1
                %If import selected, try.
                try
                    app.TempGrainsData = evalin('base', app.GrainsvariableNameEditField.Value);
                    %if successful, indicate
                    app.ImportOrRunButton.BackgroundColor='green';
                    app.ImportOrRunButton.Text='grain data loaded';
                    app.DetermineORButton.Enable = 'on';
                    app.viewdevelopmentCheckBox.Enable = 'on';
                    app.GrainsAmountLabel.Text = ['Dataset contains ' num2str(length(app.TempGrainsData)) ' grains.'];
                catch
                    if length(app.TempEbsdData)<10
                        msg = 'No variable by that name in workspace.  Import ebsd data to app on previous tab, then generate new grains';
                        errordlg(msg)
                        return
                    else
                        msg = 'No variable by that name in workspace.  Generate new grains instead';
                        errordlg(msg)
                        return
                    end
                end
            else
                %check length.
                if length(app.TempEbsdData)<10
                    msg = 'Import ebsd data first on previous tab';
                    errordlg(msg)
                else
                    %indicate progress
                    app.ImportOrRunButton.BackgroundColor='yellow';
                    app.ImportOrRunButton.Text='working...';
                    % create grains variable for all indexed phases
                    [app.TempGrainsData,app.TempEbsdData(app.Symmetries{1}.mineral).grainId] = calcGrains(app.TempEbsdData(app.Symmetries{1}.mineral),'angle',app.DegreeBoundaryEditField.Value*degree);
                    if app.CleanUpCheckBox.Value == 1
                        
                        %Remove small grains
                        ind = app.TempGrainsData.grainSize < app.CleanUpEditField.Value;
                        app.TempEbsdData(app.TempGrainsData(ind)).phase = 0;
                        app.TempEbsdData(app.TempGrainsData(ind)).grainId = 0;
                        
                        %Reidentify grains with small grains removed:
                        [app.TempGrainsData,app.TempEbsdData(app.Symmetries{1}.mineral).grainId] = calcGrains(app.TempEbsdData(app.Symmetries{1}.mineral),'angle',app.DegreeBoundaryEditField.Value*degree,'boundary','tight');
                    end
                    
                    %show finished
                    app.ImportOrRunButton.BackgroundColor='green';
                    app.ImportOrRunButton.Text='loaded';
                    %if user wants, save grains back to base workspace
                    if app.savegrainstoworkspaceandupdateCheckBox.Value==1
                        assignin('base', 'grains', app.TempGrainsData)
                        assignin('base',  app.ImportedEbsdVarName, app.TempEbsdData)
                        app.ImportOrRunButton.Text='Loaded and saved';
                        app.DetermineORButton.Enable = 'on';
                        app.viewdevelopmentCheckBox.Enable = 'on';
                        app.GrainsAmountLabel.Text = ['Dataset contains ' num2str(length(app.TempGrainsData)) ' grains.'];
                        
                    else %do nothing
                    end
                end
            end
            
        end

        % Button pushed function: PlotresultButton
        function PlotresultButtonPushed(app, event)
            %Change dropdown list values for easier handling:
            app.ORDropDown.ItemsData = [1 2 3];
            val_blackwhite = app.WhiteonblackCheckBox.Value;
            val_constsize = app.ORDropDown.Value;
            
            %Show desired type of grain boundary map to analyse OR determination success:
            if val_blackwhite == 0
                figure
                plot(app.TempEbsdData,app.TempEbsdData.bc)
                colormap gray
                hold on;
                if val_constsize == 1
                    plot(app.orbounds{1}(ismember(app.orbounds{4},app.orbounds{2},'rows')),'linecolor','r','linewidth',1,'faceAlpha',0.5)
                    plot(app.orbounds{1}(ismember(app.orbounds{4},app.orbounds{3},'rows')),'linecolor','g','linewidth',1,'faceAlpha',0.5)
                    plot(app.orbounds{1}(not(ismember(app.orbounds{4},app.orbounds{2},'rows'))),'linecolor','k','linewidth',2)
                elseif val_constsize == 2
                    plot(app.orbounds{1}(~ismember(app.orbounds{4},app.orbounds{3},'rows')),'linecolor','r','linewidth',1,'faceAlpha',0.5)
                    plot(app.orbounds{1}(not(ismember(app.orbounds{4},app.orbounds{2},'rows'))),'linecolor','k','linewidth',2)
                elseif val_constsize == 3
                    plot(app.orbounds{1}(not(ismember(app.orbounds{4},app.orbounds{2},'rows'))),'linecolor','k','linewidth',2)
                end
            elseif val_blackwhite == 1
                figure
                if val_constsize == 1
                    plot(app.orbounds{1}(ismember(app.orbounds{4},app.orbounds{2},'rows')),'linecolor','w','linewidth',2)
                    set(gca, 'color', [0 0 0])
                elseif val_constsize == 2
                    plot(app.orbounds{1}(~ismember(app.orbounds{4},app.orbounds{3},'rows')),'linecolor','w','linewidth',2)
                    set(gca, 'color', [0 0 0])
                elseif val_constsize == 3
                    plot(app.orbounds{1}(not(ismember(app.orbounds{4},app.orbounds{2},'rows'))),'linecolor','w','linewidth',2)
                    set(gca, 'color', [0 0 0])
                end
            end
            
        end

        % Button pushed function: ReconstructButton
        function ReconstructButtonPushed(app, event)
            %Indicate progress:
            app.ReconstructButton.BackgroundColor='yellow';
            app.ReconstructButton.Text='working...';
            %Calculate the parent austenite orientation for each discrete grain cluster:
            [app.TempEbsdAusData,app.devis] = recaus(app.TempEbsdData,app.TempGrainsData,app.Symmetries,app.fcc2bcc,app.ib);
            %Show finished:
            app.ReconstructButton.BackgroundColor='green';
            app.ReconstructButton.Text='Complete';
            %Enable next work and analysis phase:
            app.PlotresultsButton.Enable = 'on';
            app.SavetoworkspaceButton.Enable = 'on';
            app.ExplainSaveLabel.Enable = 'on';
            app.PlotgrainbygrainButton.Enable = 'on';
            app.recevaluationLabel.Enable = 'on';
            app.CalculateVarsButton.Enable = 'on';
            app.SavetoworkspaceButton_3.Enable = 'on';
            app.graindeviationvaluesasdevisLabel.Enable = 'on';
            %Update label describing average fit between the iteratively determined OR and the reconstruction result:
            app.recevaluationLabel.Text = ['The reconstruction resulted in an average ' num2str(round(mean(app.devis),2)) ' degree angular deviation from the experimental OR.'];
        end

        % Button pushed function: PlotresultsButton
        function PlotresultsButtonPushed(app, event)
            %Comparison of grain boundary vs. reconstruction analysis
            figure
            plot(app.TempEbsdAusData(app.TempGrainsData),app.TempEbsdAusData(app.TempGrainsData).orientations,'faceAlpha',0.5)
            hold on
            plot(app.orbounds{1}(not(ismember(app.orbounds{4},app.orbounds{2},'rows'))),'linecolor','k','linewidth',2)
            
        end

        % Value changed function: SaveFcc2bccCheckBox
        function SaveFcc2bccCheckBoxValueChanged(app, event)
            %Enable or disable plotting button depending on checkboxes:
            if app.SaveFcc2bccCheckBox.Value == 1 | app.SaveVariantsHistCheckBox.Value == 1
                app.SaveORtoworkspaceButton.Enable = 'on';
            elseif app.SaveFcc2bccCheckBox.Value == 0 & app.SaveVariantsHistCheckBox.Value == 0
                app.SaveORtoworkspaceButton.Enable = 'off';
            end
        end

        % Value changed function: SaveVariantsHistCheckBox
        function SaveVariantsHistCheckBoxValueChanged(app, event)
            %Enable or disable save button depending on checkboxes:
            if app.SaveFcc2bccCheckBox.Value == 1 | app.SaveVariantsHistCheckBox.Value == 1
                app.SaveORtoworkspaceButton.Enable = 'on';
            elseif app.SaveFcc2bccCheckBox.Value == 0 & app.SaveVariantsHistCheckBox.Value == 0
                app.SaveORtoworkspaceButton.Enable = 'off';
            end
        end

        % Button pushed function: SaveORtoworkspaceButton
        function SaveORtoworkspaceButtonPushed(app, event)
            %Save values to workspace:
            if app.SaveFcc2bccCheckBox.Value == 1
                assignin('base', 'fcc2bcc', app.fcc2bcc);
            end
            if app.SaveVariantsHistCheckBox.Value == 1
                assignin('base', 'variants_hist', app.HistVariants);
                assignin('base', 'variants_bin', [1:24]);
            end
        end

        % Button pushed function: SavetoworkspaceButton
        function SavetoworkspaceButtonPushed(app, event)
            %Save reconstruction result to workspace:
            assignin('base', 'ebsd_aus', app.TempEbsdAusData);
        end

        % Value changed function: 
        % SelecttoaddaustenitetophaselistCheckBox
        function SelecttoaddaustenitetophaselistCheckBoxValueChanged(app, event)
            %If there is no austenite in the phase list, it is necessary to add it there:
            value = app.SelecttoaddaustenitetophaselistCheckBox.Value;
            if value == 1;
                app.AusteniteListBox.Enable='off';
                app.Symmetries{2} = crystalSymmetry('m-3m', [3.6599 3.6599 3.6599], 'mineral', 'Iron fcc', 'color', 'light green');
                app.TempEbsdData.CSList{end+1} = app.Symmetries{2};
                %Update the austenite and martensite ListBoxes:
                app.AusteniteListBox.ItemsData = [];
                app.MartensiteListBox.ItemsData = [];
                app.AusteniteListBox.Items = app.TempEbsdData.mineralList(2:end);
                app.MartensiteListBox.Items = app.TempEbsdData.mineralList(2:end);
                app.AusteniteListBox.ItemsData=1:length(app.AusteniteListBox.Items);
                app.MartensiteListBox.ItemsData=1:length(app.MartensiteListBox.Items);
                app.AusteniteListBox.Value = length(app.AusteniteListBox.Items);
                
                app.TempEbsdData.phaseMap(end+1) = length(app.TempEbsdData.phaseMap+1);
                app.AusteniteLabel.Text = ['Austenite: ' app.Symmetries{2}.mineral];
            end
            if value == 0; %Undo everything if this is disabled:
                app.AusteniteListBox.Enable='on';
                app.Symmetries{2} = [];
                app.TempEbsdData.CSList(end) = [];
                app.TempEbsdData.phaseMap(end) = [];
                
                app.AusteniteListBox.ItemsData = [];
                app.MartensiteListBox.ItemsData = [];
                app.AusteniteListBox.Items = app.TempEbsdData.mineralList(2:end);
                app.MartensiteListBox.Items = app.TempEbsdData.mineralList(2:end);
                app.AusteniteListBox.ItemsData=1:length(app.AusteniteListBox.Items);
                app.MartensiteListBox.ItemsData=1:length(app.MartensiteListBox.Items);
                app.AusteniteListBox.Value = length(app.AusteniteListBox.Items);
                app.AusteniteLabel.Text = 'Austenite: ';
            end
            
        end

        % Selection changed function: GrainsdatasourceButtonGroup
        function GrainsdatasourceButtonGroupSelectionChanged2(app, event)
            if app.GeneratenewgrainsButton.Value==1 %if making new grains, ungrey 'save box'
                app.savegrainstoworkspaceandupdateCheckBox.Enable='on';
                app.CleanUpCheckBox.Enable = 'on';
                app.CleanUpEditField.Enable = 'on';
                app.pixelsLabel.Enable = 'on';
                app.EbsdVarName.Value=app.EBSDVariableNameEditField.Value;
            else %greyed out
                app.savegrainstoworkspaceandupdateCheckBox.Enable='off';
                app.CleanUpCheckBox.Enable = 'off';
                app.CleanUpEditField.Enable = 'off';
                app.pixelsLabel.Enable = 'off';
            end
            
        end

        % Button pushed function: PlotgrainbygrainButton
        function PlotgrainbygrainButtonPushed(app, event)
            %Plot a grain map showing the deviation between the austenite orientation of each grain and the corresponding cluster
            figure
            plot(app.TempGrainsData,app.devis);
        end

        % Button pushed function: CalculateVarsButton
        function CalculateVarsButtonPushed(app, event)
            %Indicate progress:
            app.CalculateVarsButton.BackgroundColor='yellow';
            app.CalculateVarsButton.Text='working...';
            %Get all the misorientations from the ferritic phase to the austenitic
            %phase:
            %fccs2bccs = inv(project2FundamentalRegion(app.TempEbsdAusData(app.TempGrainsData(app.devis>0)).orientations)).*project2FundamentalRegion(app.TempEbsdData(app.TempGrainsData(app.devis>0)).orientations);
            fccs2bccs = inv(project2FundamentalRegion(app.TempEbsdAusData(app.TempGrainsData).orientations)).*project2FundamentalRegion(app.TempEbsdData(app.TempGrainsData).orientations);
            %Define the fcc to bcc orientation relationship as by Morito et al.:
            fcc2bcc_true = orientation(rotation(rotation(app.symrots)*app.fcc2bcc(1)),app.Symmetries{1},app.Symmetries{2});
            %Calculate the angles between the misorientations and the components of the
            %full orientation relationship:
            variant_angles = angle_outer(orientation(rotation(fccs2bccs),app.Symmetries{2},1),orientation(rotation(fcc2bcc_true),app.Symmetries{2},1)) / degree;
            %Determine variant numbers corresponding to best match:
            [app.variants{1}, app.variants{2}] = min(variant_angles,[],2);
            %Rotate all misorientations back to the primary OR (described approximately by K-S)
            fcc2bcc_candidate = inv(app.symrots(app.variants{2}(app.variants{1}<3))).*orientation(rotation(fccs2bccs(app.variants{1}<3)),app.Symmetries{1},1);
            %Determine new OR as the mean orientation:
            app.fcc2bcc_rec = mean(fcc2bcc_candidate);
            %The following three lines ensure that the correct symmetrical match is always selected for the OR:
            fcc2bcc_KS = (orientation('map',Miller(1,1,1,app.Symmetries{2}),Miller(0,1,1,app.Symmetries{1}),Miller(-1,0,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{1})));
            [M2, I2] = min(angle_outer(rotation(app.fcc2bcc_rec)*rotation(app.symrots),rotation(fcc2bcc_KS)));
            app.fcc2bcc_rec = app.fcc2bcc_rec*rotation(app.symrots(I2));
            %It is perhaps easier to visualize the OR if it is described as bcc2fcc (same thing as before):
            bcc2fcc_KS = (orientation('map',Miller(0,1,1,app.Symmetries{1}),Miller(1,1,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{1}),Miller(-1,0,1,app.Symmetries{2})));
            bcc2fcc_rec = inv(app.fcc2bcc_rec(1));
            bccs2fccs = inv((app.TempEbsdData(app.TempGrainsData(app.devis>0)).orientations)).*app.TempEbsdAusData(app.TempGrainsData(app.devis>0)).orientations;
            variant_angles = angle_outer(orientation(rotation(bccs2fccs),app.Symmetries{2},1),orientation(rotation(bcc2fcc_rec),app.Symmetries{2},1)) / degree;
            [M_1, I_1] = min(variant_angles,[],2);
            bcc2fcc_candidate = inv(app.symrots(I_1(M_1<3))).*orientation(rotation(bccs2fccs(M_1<3)),app.Symmetries{1},1);
            %Determine ODF strictly as a visual aid:
            app.odf_aus = calcODF(orientation(rotation(bcc2fcc_candidate),app.Symmetries{2},1),'halfwidth',1*degree);
            %Enable new plotting and analysis functions:
            app.PlotvariantsButton.Enable = 'on';
            app.PlotORButton_4.Enable = 'on';
            app.SavetoworkspaceButton_2.Enable = 'on';
            app.PFtrueCheckBox.Enable = 'on';
            app.zoomedPFCheckBox.Enable = 'on';
            app.savevariantstrueCheckBox.Enable = 'on';
            app.saveORtrueCheckBox.Enable = 'on';
            %Show done:
            app.CalculateVarsButton.BackgroundColor='green';
            app.CalculateVarsButton.Text='Done';
        end

        % Button pushed function: PlotvariantsButton
        function PlotvariantsButtonPushed(app, event)
            figure
            plot(app.TempEbsdData(app.TempGrainsData),app.variants{2})
            colormap jet
            hold on
            plot(app.orbounds{1}(not(ismember(app.orbounds{4},app.orbounds{2},'rows'))),'linecolor','k','linewidth',2)
        end

        % Value changed function: PFtrueCheckBox
        function PFtrueCheckBoxValueChanged(app, event)
            if app.PFtrueCheckBox.Value == 1 | app.zoomedPFCheckBox.Value == 1
                app.PlotORButton_4.Enable = 'on';
            elseif app.PFtrueCheckBox.Value == 0 & app.zoomedPFCheckBox.Value == 0
                app.PlotORButton_4.Enable = 'off';
            end
        end

        % Value changed function: zoomedPFCheckBox
        function zoomedPFCheckBoxValueChanged(app, event)
            if app.PFtrueCheckBox.Value == 1 | app.zoomedPFCheckBox.Value == 1
                app.PlotORButton_4.Enable = 'on';
            elseif app.PFtrueCheckBox.Value == 0 & app.zoomedPFCheckBox.Value == 0
                app.PlotORButton_4.Enable = 'off';
            end
        end

        % Value changed function: savevariantstrueCheckBox
        function savevariantstrueCheckBoxValueChanged(app, event)
            if app.saveORtrueCheckBox.Value == 1 | app.savevariantstrueCheckBox.Value == 1
                app.SavetoworkspaceButton_2.Enable = 'on';
            elseif app.saveORtrueCheckBox.Value == 0 & app.savevariantstrueCheckBox.Value == 0
                app.SavetoworkspaceButton_2.Enable = 'off';
            end
        end

        % Value changed function: saveORtrueCheckBox
        function saveORtrueCheckBoxValueChanged(app, event)
            if app.saveORtrueCheckBox.Value == 1 | app.savevariantstrueCheckBox.Value == 1
                app.SavetoworkspaceButton_2.Enable = 'on';
            elseif app.saveORtrueCheckBox.Value == 0 & app.savevariantstrueCheckBox.Value == 0
                app.SavetoworkspaceButton_2.Enable = 'off';
            end
        end

        % Button pushed function: PlotORButton_4
        function PlotORButton_4Pushed(app, event)
            
            if app.zoomedPFCheckBox.Value == 1
                %A pole figure provides a convenient visual medium to express the near-parallelisms and orientation spread of the orientation relationship.
                %Here, that is accomplished by plotting certain martensite orientations on an austenite stereographic projection.
                %It is helpful to think about austenite as the specimen reference frame and martensite as the crystal reference frame.
                %bcc2fcc is the rotation necessary to bring the crystal (martensite) frame to the specimen (austenite) frame.
                bcc2fcc_KS = (orientation('map',Miller(0,1,1,app.Symmetries{1}),Miller(1,1,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{1}),Miller(-1,0,1,app.Symmetries{2})));
                
                z1 = getMTEXpref('xAxisDirection');
                z2 = getMTEXpref('zAxisDirection');
                
                setMTEXpref('xAxisDirection','south');
                setMTEXpref('zAxisDirection','outOfPlane');
                
                figure
                h_1 = [Miller(0,1,1,app.Symmetries{2}),Miller(0,1,1,app.Symmetries{2})];
                
                plotPDF(app.odf_aus,h_1,'contourf','grid','grid_res',3*degree)
                mtexColorMap LaboTeX
                f = gcm;
                f.currentAxes = f.children(1);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(1,1,1,app.Symmetries{2}),'marker','s','MarkerSize',50,'MarkerFaceColor','none','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','(111)\gamma')
                f.currentAxes = f.children(2);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plotPDF(orientation(rotation(inv(app.fcc2bcc_rec)),app.Symmetries{2},1),h_1,'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
                plot(Miller(1,1,1,app.Symmetries{2}),'marker','s','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','(111)\gamma')
                
                f.children(1).Title.String = 'Stereographic projection for austenite';
                f.children(2).Title.String = 'Martensite (011) planes';
                axis([0.50 0.80 -0.80 -0.50]);
                
                figure
                
                h_2 = [Miller(-1,-1,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{2})];
                plotPDF(app.odf_aus,h_2,'contourf','grid','grid_res',3*degree)
                mtexColorMap LaboTeX
                f = gcm;
                f.currentAxes = f.children(1);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(-1,0,1,app.Symmetries{2}),'marker','s','MarkerSize',50,'MarkerFaceColor','none','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','[\overline{1}01]\gamma')
                f.currentAxes = f.children(2);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plotPDF(orientation(rotation(inv(app.fcc2bcc_rec)),app.Symmetries{2},1),h_2,'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
                plot(Miller(-1,0,1,app.Symmetries{2}),'marker','s','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','[\overline{1}01]\gamma','BackgroundColor','w')
                
                f.children(1).Title.String = 'Stereographic projection for austenite';
                f.children(2).Title.String = 'Martensite [-1-1 1] directions';
                axis([-0.15 0.15 0.6 0.9]);
                
                setMTEXpref('xAxisDirection',z1);
                setMTEXpref('zAxisDirection',z2);
            end
            if app.PFtrueCheckBox.Value == 1
                figure
                plotPDF(orientation(rotation(app.symrots*app.fcc2bcc_rec(1)),app.Symmetries{1},1),[Miller(0,0,1,app.Symmetries{1}),Miller(0,1,1,app.Symmetries{1}),Miller(1,1,1,app.Symmetries{1})],'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
            end
        end

        % Button pushed function: SavetoworkspaceButton_2
        function SavetoworkspaceButton_2Pushed(app, event)
            if app.saveORtrueCheckBox.Value == 1
                assignin('base', 'fcc2bcc_rec', app.fcc2bcc_rec);
            end
            if app.savevariantstrueCheckBox.Value == 1
                assignin('base', 'M_variants', app.variants{1});
                assignin('base', 'I_variants', app.variants{2});
            end
        end

        % Button pushed function: SavetoworkspaceButton_3
        function SavetoworkspaceButton_3Pushed(app, event)
            assignin('base','devis',app.devis);
        end

        % Value changed function: ItePFtrueCheckBox
        function ItePFtrueCheckBoxValueChanged(app, event)
            if app.ItePFtrueCheckBox.Value == 1 | app.ItezoomedPFCheckBox.Value == 1
                app.PlotIteORButton.Enable = 'on';
            elseif app.ItePFtrueCheckBox.Value == 0 & app.ItezoomedPFCheckBox.Value == 0
                app.PlotIteORButton.Enable = 'off';
            end
        end

        % Value changed function: ItezoomedPFCheckBox
        function ItezoomedPFCheckBoxValueChanged(app, event)
            if app.ItePFtrueCheckBox.Value == 1 | app.ItezoomedPFCheckBox.Value == 1
                app.PlotIteORButton.Enable = 'on';
            elseif app.ItePFtrueCheckBox.Value == 0 & app.ItezoomedPFCheckBox.Value == 0
                app.PlotIteORButton.Enable = 'off';
            end
        end

        % Button pushed function: PlotIteORButton
        function PlotIteORButtonPushed(app, event)
            if app.ItezoomedPFCheckBox.Value == 1
                %A pole figure provides a convenient visual medium to express the near-parallelisms and orientation spread of the orientation relationship.
                %Here, that is accomplished by plotting certain martensite orientations on an austenite stereographic projection.
                %It is helpful to think about austenite as the specimen reference frame and martensite as the crystal reference frame.
                %bcc2fcc is the rotation necessary to bring the crystal (martensite) frame to the specimen (austenite) frame.
                bcc2fcc_KS = (orientation('map',Miller(0,1,1,app.Symmetries{1}),Miller(1,1,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{1}),Miller(-1,0,1,app.Symmetries{2})));
                
                z1 = getMTEXpref('xAxisDirection');
                z2 = getMTEXpref('zAxisDirection');
                
                setMTEXpref('xAxisDirection','south');
                setMTEXpref('zAxisDirection','outOfPlane');
                
                figure
                h_1 = [Miller(0,1,1,app.Symmetries{2}),Miller(0,1,1,app.Symmetries{2})];
                
                plotPDF(app.bcc2fcc_odf,h_1,'contourf','grid','grid_res',3*degree)
                mtexColorMap LaboTeX
                f = gcm;
                f.currentAxes = f.children(1);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(1,1,1,app.Symmetries{2}),'marker','s','MarkerSize',50,'MarkerFaceColor','none','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','(111)\gamma')
                f.currentAxes = f.children(2);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plotPDF(orientation(rotation(inv(app.fcc2bcc)),app.Symmetries{2},1),h_1,'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
                plot(Miller(1,1,1,app.Symmetries{2}),'marker','s','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','(111)\gamma')
                
                f.children(1).Title.String = 'Stereographic projection for austenite';
                f.children(2).Title.String = 'Martensite (011) planes';
                axis([0.50 0.80 -0.80 -0.50]);
                
                figure
                
                h_2 = [Miller(-1,-1,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{2})];
                plotPDF(app.bcc2fcc_odf,h_2,'contourf','grid','grid_res',3*degree)
                mtexColorMap LaboTeX
                f = gcm;
                f.currentAxes = f.children(1);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(-1,0,1,app.Symmetries{2}),'marker','s','MarkerSize',50,'MarkerFaceColor','none','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','[\overline{1}01]\gamma')
                f.currentAxes = f.children(2);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plotPDF(orientation(rotation(inv(app.fcc2bcc)),app.Symmetries{2},1),h_2,'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
                plot(Miller(-1,0,1,app.Symmetries{2}),'marker','s','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','[\overline{1}01]\gamma','BackgroundColor','w')
                
                f.children(1).Title.String = 'Stereographic projection for austenite';
                f.children(2).Title.String = 'Martensite [-1-1 1] directions';
                axis([-0.15 0.15 0.6 0.9]);
                
                setMTEXpref('xAxisDirection',z1);
                setMTEXpref('zAxisDirection',z2);
            end
            if app.ItePFtrueCheckBox.Value == 1
                figure
                plotPDF(orientation(rotation(app.symrots*app.fcc2bcc(1)),app.Symmetries{1},1),[Miller(0,0,1,app.Symmetries{1}),Miller(0,1,1,app.Symmetries{1}),Miller(1,1,1,app.Symmetries{1})],'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
            end
        end

        % Button pushed function: SavetoworkspaceButton_4
        function SavetoworkspaceButton_4Pushed(app, event)
            %Save values to workspace:
            if app.SaveFcc2bccCheckBox.Value == 1
                assignin('base', 'mcl', app.ib);
            end
        end

        % Button pushed function: TriplepointORButton
        function TriplepointORButtonPushed(app, event)
            %Indicate progress:
            app.TriplepointORButton.BackgroundColor='yellow';
            app.TriplepointORButton.Text='working...';
            %Call the or determination function:
            [app.fcc2bcc_triple,app.bcc2fcc_odf_triple] = determineor_triple(app.Symmetries,app.TempEbsdData,app.TriplepointdevelopmentCheckBox.Value);
            
            %Show finished:
            app.TriplepointORButton.BackgroundColor='green';
            app.TriplepointORButton.Text='OR determined';
            %Enable the next work and analysis phase:
            %             app.PlotresultButton.Enable = 'on';
            %             app.SaveFcc2bccCheckBox.Enable = 'on';
            %             app.SaveVariantsHistCheckBox.Enable = 'on';
            %             app.ORDropDown.Enable = 'on';
            %             app.SaveORtoworkspaceButton.Enable = 'on';
            %             app.WhiteonblackCheckBox.Enable = 'on';
            app.AusMisoPairsButton.Enable = 'on';
            
        end

        % Callback function
        function TriplepointPlotIteORButtonPushed(app, event)
            if app.TriplepointItezoomedPFCheckBox.Value == 1
                %A pole figure provides a convenient visual medium to express the near-parallelisms and orientation spread of the orientation relationship.
                %Here, that is accomplished by plotting certain martensite orientations on an austenite stereographic projection.
                %It is helpful to think about austenite as the specimen reference frame and martensite as the crystal reference frame.
                %bcc2fcc is the rotation necessary to bring the crystal (martensite) frame to the specimen (austenite) frame.
                bcc2fcc_KS = (orientation('map',Miller(0,1,1,app.Symmetries{1}),Miller(1,1,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{1}),Miller(-1,0,1,app.Symmetries{2})));
                
                z1 = getMTEXpref('xAxisDirection');
                z2 = getMTEXpref('zAxisDirection');
                
                setMTEXpref('xAxisDirection','south');
                setMTEXpref('zAxisDirection','outOfPlane');
                
                figure
                h_1 = [Miller(0,1,1,app.Symmetries{2}),Miller(0,1,1,app.Symmetries{2})];
                
                plotPDF(app.bcc2fcc_odf_triple,h_1,'contourf','grid','grid_res',3*degree)
                
                mtexColorMap LaboTeX
                f = gcm;
                f.currentAxes = f.children(1);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(1,1,1,app.Symmetries{2}),'marker','s','MarkerSize',50,'MarkerFaceColor','none','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','(111)\gamma')
                f.currentAxes = f.children(2);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(1,1,1,app.Symmetries{2}),'marker','s','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','(111)\gamma')
                
                plotPDF(orientation(rotation(inv(app.fcc2bcc_triple)),app.Symmetries{2},1),h_1,'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
                
                f.children(1).Title.String = 'Stereographic projection for austenite';
                f.children(2).Title.String = 'Martensite (011) planes';
                axis([0.50 0.80 -0.80 -0.50]);
                
                figure
                
                h_2 = [Miller(-1,-1,1,app.Symmetries{2}),Miller(-1,-1,1,app.Symmetries{2})];
                plotPDF(app.bcc2fcc_odf_triple,h_2,'contourf','grid','grid_res',3*degree)
                
                mtexColorMap LaboTeX
                f = gcm;
                f.currentAxes = f.children(1);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(-1,0,1,app.Symmetries{2}),'marker','s','MarkerSize',50,'MarkerFaceColor','none','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','[\overline{1}01]\gamma')
                f.currentAxes = f.children(2);
                hold on;
                plot((xvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - yvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((xvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector + zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot((yvector - zvector),'plane','color','k','linewidth',1,'linestyle','--')
                plot(Miller(-1,0,1,app.Symmetries{2}),'marker','s','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white','label','[\overline{1}01]\gamma','BackgroundColor','w')
                
                plotPDF(orientation(rotation(inv(app.fcc2bcc_triple)),app.Symmetries{2},1),h_2,'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
                
                f.children(1).Title.String = 'Stereographic projection for austenite';
                f.children(2).Title.String = 'Martensite [-1-1 1] directions';
                axis([-0.15 0.15 0.6 0.9]);
                
                setMTEXpref('xAxisDirection',z1);
                setMTEXpref('zAxisDirection',z2);
            end
            if app.TriplepointItePFtrueCheckBox.Value == 1
                figure
                plotPDF(orientation(rotation(rotation(app.Symmetries{1}.properGroup)*app.fcc2bcc_triple(1)),app.Symmetries{1},1),[Miller(0,0,1,app.Symmetries{1}),Miller(0,1,1,app.Symmetries{1}),Miller(1,1,1,app.Symmetries{1})],'marker','o','MarkerSize',6,'MarkerFaceColor','white','MarkerEdgeColor',[0 0 0],'LineWidth',2,'MarkerColor','white')
            end
        end

        % Button pushed function: AusMisoPairsButton
        function AusMisoPairsButtonPushed(app, event)
            
            app.AusMisoPairsButton.BackgroundColor='yellow';
            app.AusMisoPairsButton.Text='working...';
            
            [app.TempEbsdAus_Pairs, app.TempEbsdAus_Triple,app.V_rec,app.F_rec,app.TripleVariants] = rec_aus_triple(app.TempEbsdData,app.fcc2bcc_triple,app.Symmetries);
            %Show finished:
            app.AusMisoPairsButton.BackgroundColor='green';
            app.AusMisoPairsButton.Text='Complete';
            
            app.TriplePointPlotButton.Enable = 'on';
            app.BandcontrastonlyButton.Enable = 'on';
            app.AusteniteindividualmisorientationpairsButton.Enable = 'on';
            app.AustenitetriplepointsButton.Enable = 'on';
            app.BlocksButton.Enable = 'on';
            app.PacketsButton.Enable = 'on';
            app.PAGSButton.Enable = 'on';
            app.NoBandContrastCheckBox.Enable = 'on';
            
            app.AusTriplePointSave.Enable = 'on';
            app.TriplepointSaveFcc2bccCheckBox.Enable = 'on';
            app.TriplepointSaveVariantsHistCheckBox.Enable = 'on';
            app.ExplainSaveLabel_4.Enable = 'on';
            app.TriplepointSaveFcc2bccCheckBox_2.Enable = 'on';
            app.TriplepointSaveFcc2bccCheckBox_3.Enable = 'on';
        end

        % Button pushed function: TriplePointPlotButton
        function TriplePointPlotButtonPushed(app, event)
            
            %Show desired type of grain boundary map to analyse OR determination success:
            
            symmetry2_string = app.Symmetries{2}.mineral;

            if app.NoBandContrastCheckBox.Value ==0
                figure
                plot(app.TempEbsdAus_Triple,app.TempEbsdAus_Triple.bc)
                colormap gray
                hold on;
            else
                figure
            end
            if app.AusteniteindividualmisorientationpairsButton.Value == 1
                plot(app.TempEbsdAus_Pairs(symmetry2_string),app.TempEbsdAus_Pairs(symmetry2_string).orientations)
            elseif app.AustenitetriplepointsButton.Value == 1
                plot(app.TempEbsdAus_Triple(symmetry2_string),app.TempEbsdAus_Triple(symmetry2_string).orientations)
            end
            
            if app.BlocksButton.Value == 1
                ph = patch('Vertices', app.V_rec{1}, 'Faces', app.F_rec{1});
                set(ph,'LineWidth',1,'EdgeColor','green')
                ph = patch('Vertices', app.V_rec{2}, 'Faces', app.F_rec{2});
                set(ph,'LineWidth',2,'EdgeColor','red')
                ph = patch('Vertices', app.V_rec{3}, 'Faces', app.F_rec{3});
                set(ph,'LineWidth',2,'EdgeColor','black')
            elseif app.PacketsButton.Value == 1
                ph = patch('Vertices', app.V_rec{2}, 'Faces', app.F_rec{2});
                set(ph,'LineWidth',2,'EdgeColor','red')
                ph = patch('Vertices', app.V_rec{3}, 'Faces', app.F_rec{3});
                set(ph,'LineWidth',2,'EdgeColor','black')
            elseif app.PAGSButton.Value == 1
                ph = patch('Vertices', app.V_rec{3}, 'Faces', app.F_rec{3});
                set(ph,'LineWidth',2)
            end
        end

        % Button pushed function: AusTriplePointSave
        function AusTriplePointSaveButtonPushed(app, event)
            if app.TriplepointSaveFcc2bccCheckBox.Value == 1
                assignin('base', 'fcc2bcc_triple', app.fcc2bcc_triple)
            end
            if app.TriplepointSaveVariantsHistCheckBox.Value == 1
                assignin('base', 'variants', app.TripleVariants)
            end
            if app.TriplepointSaveFcc2bccCheckBox_2.Value == 1
                assignin('base', 'ebsd_aus_p', app.TempEbsdAus_Pairs)
            end
            if app.TriplepointSaveFcc2bccCheckBox_2.Value == 1
                assignin('base', 'ebsd_aus_triple', app.TempEbsdAus_Triple)
            end
        end
    end

    % App initialization and construction
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure
            app.UIFigure = uifigure;
            app.UIFigure.Position = [100 100 659 497];
            app.UIFigure.Name = 'UI Figure';

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Position = [10 10 640 479];

            % Create EBSDmapsTab
            app.EBSDmapsTab = uitab(app.TabGroup);
            app.EBSDmapsTab.Title = 'EBSD maps';

            % Create EBSDVariableNameEditFieldLabel
            app.EBSDVariableNameEditFieldLabel = uilabel(app.EBSDmapsTab);
            app.EBSDVariableNameEditFieldLabel.HorizontalAlignment = 'right';
            app.EBSDVariableNameEditFieldLabel.Position = [131.03125 383 121 15];
            app.EBSDVariableNameEditFieldLabel.Text = 'EBSD Variable Name';

            % Create EBSDVariableNameEditField
            app.EBSDVariableNameEditField = uieditfield(app.EBSDmapsTab, 'text');
            app.EBSDVariableNameEditField.Position = [267.03125 379 100 22];
            app.EBSDVariableNameEditField.Value = 'ebsd';

            % Create MartensiteListBoxLabel
            app.MartensiteListBoxLabel = uilabel(app.EBSDmapsTab);
            app.MartensiteListBoxLabel.BackgroundColor = [0.9373 0.9373 0.9373];
            app.MartensiteListBoxLabel.HorizontalAlignment = 'right';
            app.MartensiteListBoxLabel.Position = [35 312 62 15];
            app.MartensiteListBoxLabel.Text = 'Martensite';

            % Create MartensiteListBox
            app.MartensiteListBox = uilistbox(app.EBSDmapsTab);
            app.MartensiteListBox.ValueChangedFcn = createCallbackFcn(app, @MartensiteListBoxValueChanged, true);
            app.MartensiteListBox.BackgroundColor = [0.9373 0.9373 0.9373];
            app.MartensiteListBox.Position = [120 253 148 74];
            app.MartensiteListBox.Value = 'Item 2';

            % Create GetPhaseListButton
            app.GetPhaseListButton = uibutton(app.EBSDmapsTab, 'push');
            app.GetPhaseListButton.ButtonPushedFcn = createCallbackFcn(app, @GetPhaseListButtonPushed, true);
            app.GetPhaseListButton.BackgroundColor = [1 1 1];
            app.GetPhaseListButton.Position = [373 379 120 22];
            app.GetPhaseListButton.Text = 'Get Phase List';

            % Create SelectPhasesText
            app.SelectPhasesText = uilabel(app.EBSDmapsTab);
            app.SelectPhasesText.Position = [45 336 273 15];
            app.SelectPhasesText.Text = 'Select correct phase for martensite and austenite';

            % Create AusteniteListBoxLabel
            app.AusteniteListBoxLabel = uilabel(app.EBSDmapsTab);
            app.AusteniteListBoxLabel.BackgroundColor = [0.9373 0.9373 0.9373];
            app.AusteniteListBoxLabel.HorizontalAlignment = 'right';
            app.AusteniteListBoxLabel.Position = [348 312 56 15];
            app.AusteniteListBoxLabel.Text = 'Austenite';

            % Create AusteniteListBox
            app.AusteniteListBox = uilistbox(app.EBSDmapsTab);
            app.AusteniteListBox.ValueChangedFcn = createCallbackFcn(app, @AusteniteListBoxValueChanged, true);
            app.AusteniteListBox.BackgroundColor = [0.9373 0.9373 0.9373];
            app.AusteniteListBox.Position = [427 253 148 74];
            app.AusteniteListBox.Value = 'Item 2';

            % Create CurrentlyselectedphasesLabel
            app.CurrentlyselectedphasesLabel = uilabel(app.EBSDmapsTab);
            app.CurrentlyselectedphasesLabel.Position = [45 165 150 15];
            app.CurrentlyselectedphasesLabel.Text = 'Currently selected phases:';

            % Create MartensiteLabel
            app.MartensiteLabel = uilabel(app.EBSDmapsTab);
            app.MartensiteLabel.Position = [45 137 383 15];
            app.MartensiteLabel.Text = 'Martensite:';

            % Create AusteniteLabel
            app.AusteniteLabel = uilabel(app.EBSDmapsTab);
            app.AusteniteLabel.Position = [45 106 383 15];
            app.AusteniteLabel.Text = 'Austenite:';

            % Create SelecttoaddaustenitetophaselistCheckBox
            app.SelecttoaddaustenitetophaselistCheckBox = uicheckbox(app.EBSDmapsTab);
            app.SelecttoaddaustenitetophaselistCheckBox.ValueChangedFcn = createCallbackFcn(app, @SelecttoaddaustenitetophaselistCheckBoxValueChanged, true);
            app.SelecttoaddaustenitetophaselistCheckBox.Text = 'Select to add austenite to phase list';
            app.SelecttoaddaustenitetophaselistCheckBox.Position = [35 221 215 15];

            % Create Rev1Label
            app.Rev1Label = uilabel(app.EBSDmapsTab);
            app.Rev1Label.Enable = 'off';
            app.Rev1Label.Position = [596 441 37 15];
            app.Rev1Label.Text = 'Rev 1';

            % Create PAGsviaMCLTab
            app.PAGsviaMCLTab = uitab(app.TabGroup);
            app.PAGsviaMCLTab.Title = 'PAGs via MCL';

            % Create OrientationrelationshipdeterminationPanel
            app.OrientationrelationshipdeterminationPanel = uipanel(app.PAGsviaMCLTab);
            app.OrientationrelationshipdeterminationPanel.Title = 'Orientation relationship determination';
            app.OrientationrelationshipdeterminationPanel.Position = [1 190 639 119];

            % Create DetermineORButton
            app.DetermineORButton = uibutton(app.OrientationrelationshipdeterminationPanel, 'push');
            app.DetermineORButton.ButtonPushedFcn = createCallbackFcn(app, @DetermineORButtonPushed, true);
            app.DetermineORButton.BackgroundColor = [1 1 1];
            app.DetermineORButton.Enable = 'off';
            app.DetermineORButton.Position = [45 64 129 22];
            app.DetermineORButton.Text = 'Determine OR';

            % Create PlotresultButton
            app.PlotresultButton = uibutton(app.OrientationrelationshipdeterminationPanel, 'push');
            app.PlotresultButton.ButtonPushedFcn = createCallbackFcn(app, @PlotresultButtonPushed, true);
            app.PlotresultButton.BackgroundColor = [1 1 1];
            app.PlotresultButton.Enable = 'off';
            app.PlotresultButton.Position = [186 64 100 22];
            app.PlotresultButton.Text = 'Plot result';

            % Create viewdevelopmentCheckBox
            app.viewdevelopmentCheckBox = uicheckbox(app.OrientationrelationshipdeterminationPanel);
            app.viewdevelopmentCheckBox.Enable = 'off';
            app.viewdevelopmentCheckBox.Text = 'view development';
            app.viewdevelopmentCheckBox.Position = [47 48 127 15];
            app.viewdevelopmentCheckBox.Value = true;

            % Create SaveORtoworkspaceButton
            app.SaveORtoworkspaceButton = uibutton(app.OrientationrelationshipdeterminationPanel, 'push');
            app.SaveORtoworkspaceButton.ButtonPushedFcn = createCallbackFcn(app, @SaveORtoworkspaceButtonPushed, true);
            app.SaveORtoworkspaceButton.BackgroundColor = [1 1 1];
            app.SaveORtoworkspaceButton.Enable = 'off';
            app.SaveORtoworkspaceButton.Position = [45 18 129 22];
            app.SaveORtoworkspaceButton.Text = 'Save to workspace';

            % Create SaveFcc2bccCheckBox
            app.SaveFcc2bccCheckBox = uicheckbox(app.OrientationrelationshipdeterminationPanel);
            app.SaveFcc2bccCheckBox.ValueChangedFcn = createCallbackFcn(app, @SaveFcc2bccCheckBoxValueChanged, true);
            app.SaveFcc2bccCheckBox.Enable = 'off';
            app.SaveFcc2bccCheckBox.Text = 'orientation relationship as fcc2bcc';
            app.SaveFcc2bccCheckBox.Position = [186 31 208 15];
            app.SaveFcc2bccCheckBox.Value = true;

            % Create SaveVariantsHistCheckBox
            app.SaveVariantsHistCheckBox = uicheckbox(app.OrientationrelationshipdeterminationPanel);
            app.SaveVariantsHistCheckBox.ValueChangedFcn = createCallbackFcn(app, @SaveVariantsHistCheckBoxValueChanged, true);
            app.SaveVariantsHistCheckBox.Enable = 'off';
            app.SaveVariantsHistCheckBox.Text = 'variant histogram as [variants_hist, variants_bin]';
            app.SaveVariantsHistCheckBox.Position = [186 13 286 15];
            app.SaveVariantsHistCheckBox.Value = true;

            % Create WhiteonblackCheckBox
            app.WhiteonblackCheckBox = uicheckbox(app.OrientationrelationshipdeterminationPanel);
            app.WhiteonblackCheckBox.Enable = 'off';
            app.WhiteonblackCheckBox.Text = 'White on black';
            app.WhiteonblackCheckBox.Position = [294 56 102 15];

            % Create ORDropDown
            app.ORDropDown = uidropdown(app.OrientationrelationshipdeterminationPanel);
            app.ORDropDown.Items = {'Blocks', 'Packets', 'PAGS'};
            app.ORDropDown.ItemsData = {'1', '2', '3'};
            app.ORDropDown.Enable = 'off';
            app.ORDropDown.Position = [294 72 100 22];
            app.ORDropDown.Value = '1';

            % Create PlotIteORButton
            app.PlotIteORButton = uibutton(app.OrientationrelationshipdeterminationPanel, 'push');
            app.PlotIteORButton.ButtonPushedFcn = createCallbackFcn(app, @PlotIteORButtonPushed, true);
            app.PlotIteORButton.BackgroundColor = [1 1 1];
            app.PlotIteORButton.Enable = 'off';
            app.PlotIteORButton.Position = [404 64 100 22];
            app.PlotIteORButton.Text = 'Plot OR';

            % Create ItezoomedPFCheckBox
            app.ItezoomedPFCheckBox = uicheckbox(app.OrientationrelationshipdeterminationPanel);
            app.ItezoomedPFCheckBox.ValueChangedFcn = createCallbackFcn(app, @ItezoomedPFCheckBoxValueChanged, true);
            app.ItezoomedPFCheckBox.Enable = 'off';
            app.ItezoomedPFCheckBox.Text = 'with ODF, zoomed';
            app.ItezoomedPFCheckBox.Position = [513 58 116 15];
            app.ItezoomedPFCheckBox.Value = true;

            % Create ItePFtrueCheckBox
            app.ItePFtrueCheckBox = uicheckbox(app.OrientationrelationshipdeterminationPanel);
            app.ItePFtrueCheckBox.ValueChangedFcn = createCallbackFcn(app, @ItePFtrueCheckBoxValueChanged, true);
            app.ItePFtrueCheckBox.Enable = 'off';
            app.ItePFtrueCheckBox.Text = 'as pole figure';
            app.ItePFtrueCheckBox.Position = [513 77 116 15];
            app.ItePFtrueCheckBox.Value = true;

            % Create ConstructundirectedgraphandcallMCLPanel
            app.ConstructundirectedgraphandcallMCLPanel = uipanel(app.PAGsviaMCLTab);
            app.ConstructundirectedgraphandcallMCLPanel.Title = 'Construct undirected graph and call MCL';
            app.ConstructundirectedgraphandcallMCLPanel.Position = [1 109 639 82];

            % Create CallMCLButton
            app.CallMCLButton = uibutton(app.ConstructundirectedgraphandcallMCLPanel, 'push');
            app.CallMCLButton.ButtonPushedFcn = createCallbackFcn(app, @CallMCLButtonPushed, true);
            app.CallMCLButton.BackgroundColor = [1 1 1];
            app.CallMCLButton.Enable = 'off';
            app.CallMCLButton.Position = [45 31 129 22];
            app.CallMCLButton.Text = 'Call MCL';

            % Create InflationpowerEditFieldLabel
            app.InflationpowerEditFieldLabel = uilabel(app.ConstructundirectedgraphandcallMCLPanel);
            app.InflationpowerEditFieldLabel.HorizontalAlignment = 'right';
            app.InflationpowerEditFieldLabel.Enable = 'off';
            app.InflationpowerEditFieldLabel.Position = [224 35 85 15];
            app.InflationpowerEditFieldLabel.Text = 'Inflation power';

            % Create InflationpowerEditField
            app.InflationpowerEditField = uieditfield(app.ConstructundirectedgraphandcallMCLPanel, 'numeric');
            app.InflationpowerEditField.Limits = [1 3];
            app.InflationpowerEditField.HorizontalAlignment = 'center';
            app.InflationpowerEditField.Enable = 'off';
            app.InflationpowerEditField.Position = [191 31 34 22];
            app.InflationpowerEditField.Value = 1.6;

            % Create MCLLabel
            app.MCLLabel = uilabel(app.ConstructundirectedgraphandcallMCLPanel);
            app.MCLLabel.Position = [45 10 341 14];
            app.MCLLabel.Text = '';

            % Create SavetoworkspaceButton_4
            app.SavetoworkspaceButton_4 = uibutton(app.ConstructundirectedgraphandcallMCLPanel, 'push');
            app.SavetoworkspaceButton_4.ButtonPushedFcn = createCallbackFcn(app, @SavetoworkspaceButton_4Pushed, true);
            app.SavetoworkspaceButton_4.BackgroundColor = [1 1 1];
            app.SavetoworkspaceButton_4.Enable = 'off';
            app.SavetoworkspaceButton_4.Position = [324 30 129 22];
            app.SavetoworkspaceButton_4.Text = 'Save to workspace';

            % Create ExplainSaveLabel_2
            app.ExplainSaveLabel_2 = uilabel(app.ConstructundirectedgraphandcallMCLPanel);
            app.ExplainSaveLabel_2.Enable = 'off';
            app.ExplainSaveLabel_2.Position = [465 34 76 15];
            app.ExplainSaveLabel_2.Text = 'MCL clusters';

            % Create ReconstructparentaustenitePanel
            app.ReconstructparentaustenitePanel = uipanel(app.PAGsviaMCLTab);
            app.ReconstructparentaustenitePanel.Title = 'Reconstruct parent austenite';
            app.ReconstructparentaustenitePanel.Position = [1 0 639 110];

            % Create ReconstructButton
            app.ReconstructButton = uibutton(app.ReconstructparentaustenitePanel, 'push');
            app.ReconstructButton.ButtonPushedFcn = createCallbackFcn(app, @ReconstructButtonPushed, true);
            app.ReconstructButton.BackgroundColor = [1 1 1];
            app.ReconstructButton.Enable = 'off';
            app.ReconstructButton.Position = [45 56 129 22];
            app.ReconstructButton.Text = 'Reconstruct';

            % Create PlotresultsButton
            app.PlotresultsButton = uibutton(app.ReconstructparentaustenitePanel, 'push');
            app.PlotresultsButton.ButtonPushedFcn = createCallbackFcn(app, @PlotresultsButtonPushed, true);
            app.PlotresultsButton.BackgroundColor = [1 1 1];
            app.PlotresultsButton.Enable = 'off';
            app.PlotresultsButton.Position = [186 56 100 22];
            app.PlotresultsButton.Text = 'Plot results';

            % Create SavetoworkspaceButton
            app.SavetoworkspaceButton = uibutton(app.ReconstructparentaustenitePanel, 'push');
            app.SavetoworkspaceButton.ButtonPushedFcn = createCallbackFcn(app, @SavetoworkspaceButtonPushed, true);
            app.SavetoworkspaceButton.BackgroundColor = [1 1 1];
            app.SavetoworkspaceButton.Enable = 'off';
            app.SavetoworkspaceButton.Position = [45 24 129 22];
            app.SavetoworkspaceButton.Text = 'Save to workspace';

            % Create ExplainSaveLabel
            app.ExplainSaveLabel = uilabel(app.ReconstructparentaustenitePanel);
            app.ExplainSaveLabel.Enable = 'off';
            app.ExplainSaveLabel.Position = [186 28 163 15];
            app.ExplainSaveLabel.Text = 'orientation map as ebsd_aus';

            % Create GrainsdatasourceButtonGroup
            app.GrainsdatasourceButtonGroup = uibuttongroup(app.PAGsviaMCLTab);
            app.GrainsdatasourceButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @GrainsdatasourceButtonGroupSelectionChanged2, true);
            app.GrainsdatasourceButtonGroup.Title = 'Grains data source';
            app.GrainsdatasourceButtonGroup.Position = [1 308 639 147];

            % Create ImportGrainDataButton
            app.ImportGrainDataButton = uiradiobutton(app.GrainsdatasourceButtonGroup);
            app.ImportGrainDataButton.Text = 'Import Grain Data';
            app.ImportGrainDataButton.Position = [11 105 117.375 15];
            app.ImportGrainDataButton.Value = true;

            % Create GeneratenewgrainsButton
            app.GeneratenewgrainsButton = uiradiobutton(app.GrainsdatasourceButtonGroup);
            app.GeneratenewgrainsButton.Text = 'Generate new grains';
            app.GeneratenewgrainsButton.Position = [11 65 133.40625 15];

            % Create ORLabel
            app.ORLabel = uilabel(app.GrainsdatasourceButtonGroup);
            app.ORLabel.FontWeight = 'bold';
            app.ORLabel.Position = [135 87 25 15];
            app.ORLabel.Text = 'OR';

            % Create DegreeBoundaryEditFieldLabel
            app.DegreeBoundaryEditFieldLabel = uilabel(app.GrainsdatasourceButtonGroup);
            app.DegreeBoundaryEditFieldLabel.HorizontalAlignment = 'right';
            app.DegreeBoundaryEditFieldLabel.Position = [173 63 100 15];
            app.DegreeBoundaryEditFieldLabel.Text = 'Degree Boundary';

            % Create DegreeBoundaryEditField
            app.DegreeBoundaryEditField = uieditfield(app.GrainsdatasourceButtonGroup, 'numeric');
            app.DegreeBoundaryEditField.Limits = [0.5 10];
            app.DegreeBoundaryEditField.Position = [147 60 24 22];
            app.DegreeBoundaryEditField.Value = 3;

            % Create GrainsvariableNameEditFieldLabel
            app.GrainsvariableNameEditFieldLabel = uilabel(app.GrainsdatasourceButtonGroup);
            app.GrainsvariableNameEditFieldLabel.HorizontalAlignment = 'right';
            app.GrainsvariableNameEditFieldLabel.Position = [135 105 122 15];
            app.GrainsvariableNameEditFieldLabel.Text = 'Grains variable Name';

            % Create GrainsvariableNameEditField
            app.GrainsvariableNameEditField = uieditfield(app.GrainsdatasourceButtonGroup, 'text');
            app.GrainsvariableNameEditField.Position = [266 102 87 22];
            app.GrainsvariableNameEditField.Value = 'grains';

            % Create savegrainstoworkspaceandupdateCheckBox
            app.savegrainstoworkspaceandupdateCheckBox = uicheckbox(app.GrainsdatasourceButtonGroup);
            app.savegrainstoworkspaceandupdateCheckBox.Enable = 'off';
            app.savegrainstoworkspaceandupdateCheckBox.Text = 'save ''grains'' to workspace and update';
            app.savegrainstoworkspaceandupdateCheckBox.Position = [30 41 227.375 15];
            app.savegrainstoworkspaceandupdateCheckBox.Value = true;

            % Create EbsdVarName
            app.EbsdVarName = uieditfield(app.GrainsdatasourceButtonGroup, 'text');
            app.EbsdVarName.Editable = 'off';
            app.EbsdVarName.Enable = 'off';
            app.EbsdVarName.Position = [258 36 96 22];

            % Create ImportOrRunButton
            app.ImportOrRunButton = uibutton(app.GrainsdatasourceButtonGroup, 'push');
            app.ImportOrRunButton.ButtonPushedFcn = createCallbackFcn(app, @ImportOrRunButtonPushed, true);
            app.ImportOrRunButton.BackgroundColor = [1 1 1];
            app.ImportOrRunButton.Position = [45 11 129 22];
            app.ImportOrRunButton.Text = 'Import Or Run';

            % Create GrainsAmountLabel
            app.GrainsAmountLabel = uilabel(app.GrainsdatasourceButtonGroup);
            app.GrainsAmountLabel.Position = [191 15 224 15];
            app.GrainsAmountLabel.Text = '';

            % Create CleanUpCheckBox
            app.CleanUpCheckBox = uicheckbox(app.GrainsdatasourceButtonGroup);
            app.CleanUpCheckBox.Enable = 'off';
            app.CleanUpCheckBox.Text = 'Clean up grains smaller than';
            app.CleanUpCheckBox.Position = [287 63 179 15];
            app.CleanUpCheckBox.Value = true;

            % Create CleanUpEditField
            app.CleanUpEditField = uieditfield(app.GrainsdatasourceButtonGroup, 'numeric');
            app.CleanUpEditField.Enable = 'off';
            app.CleanUpEditField.Position = [465 60 19 22];
            app.CleanUpEditField.Value = 4;

            % Create pixelsLabel
            app.pixelsLabel = uilabel(app.GrainsdatasourceButtonGroup);
            app.pixelsLabel.Enable = 'off';
            app.pixelsLabel.Position = [491 63 37 15];
            app.pixelsLabel.Text = 'pixels';

            % Create Rev1Label_2
            app.Rev1Label_2 = uilabel(app.GrainsdatasourceButtonGroup);
            app.Rev1Label_2.Enable = 'off';
            app.Rev1Label_2.Position = [592 106 37 15];
            app.Rev1Label_2.Text = 'Rev 1';

            % Create MCLAnalysisTab
            app.MCLAnalysisTab = uitab(app.TabGroup);
            app.MCLAnalysisTab.Title = 'MCL Analysis';

            % Create Rev1Label_3
            app.Rev1Label_3 = uilabel(app.MCLAnalysisTab);
            app.Rev1Label_3.Enable = 'off';
            app.Rev1Label_3.Position = [596 441 37 15];
            app.Rev1Label_3.Text = 'Rev 1';

            % Create ResolutionVariantsPanel
            app.ResolutionVariantsPanel = uipanel(app.MCLAnalysisTab);
            app.ResolutionVariantsPanel.Title = 'Analyze variants and recalculate orientation relationship from reconstruction result';
            app.ResolutionVariantsPanel.Position = [1 187 587 168];

            % Create CalculateVarsButton
            app.CalculateVarsButton = uibutton(app.ResolutionVariantsPanel, 'push');
            app.CalculateVarsButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateVarsButtonPushed, true);
            app.CalculateVarsButton.BackgroundColor = [1 1 1];
            app.CalculateVarsButton.Enable = 'off';
            app.CalculateVarsButton.Position = [12 113 129 22];
            app.CalculateVarsButton.Text = 'Calculate';

            % Create PlotvariantsButton
            app.PlotvariantsButton = uibutton(app.ResolutionVariantsPanel, 'push');
            app.PlotvariantsButton.ButtonPushedFcn = createCallbackFcn(app, @PlotvariantsButtonPushed, true);
            app.PlotvariantsButton.BackgroundColor = [1 1 1];
            app.PlotvariantsButton.Enable = 'off';
            app.PlotvariantsButton.Position = [160 113 129 22];
            app.PlotvariantsButton.Text = 'Plot variants';

            % Create PlotORButton_4
            app.PlotORButton_4 = uibutton(app.ResolutionVariantsPanel, 'push');
            app.PlotORButton_4.ButtonPushedFcn = createCallbackFcn(app, @PlotORButton_4Pushed, true);
            app.PlotORButton_4.BackgroundColor = [1 1 1];
            app.PlotORButton_4.Enable = 'off';
            app.PlotORButton_4.Position = [160 73 129 22];
            app.PlotORButton_4.Text = 'Plot OR';

            % Create PFtrueCheckBox
            app.PFtrueCheckBox = uicheckbox(app.ResolutionVariantsPanel);
            app.PFtrueCheckBox.ValueChangedFcn = createCallbackFcn(app, @PFtrueCheckBoxValueChanged, true);
            app.PFtrueCheckBox.Enable = 'off';
            app.PFtrueCheckBox.Text = 'as pole figure for 001, 110 and 111 orientations';
            app.PFtrueCheckBox.Position = [297 87 279 15];
            app.PFtrueCheckBox.Value = true;

            % Create zoomedPFCheckBox
            app.zoomedPFCheckBox = uicheckbox(app.ResolutionVariantsPanel);
            app.zoomedPFCheckBox.ValueChangedFcn = createCallbackFcn(app, @zoomedPFCheckBoxValueChanged, true);
            app.zoomedPFCheckBox.Enable = 'off';
            app.zoomedPFCheckBox.Text = 'with ODF, zoomed in on plane parallelisms';
            app.zoomedPFCheckBox.Position = [297 66 256 15];
            app.zoomedPFCheckBox.Value = true;

            % Create SavetoworkspaceButton_2
            app.SavetoworkspaceButton_2 = uibutton(app.ResolutionVariantsPanel, 'push');
            app.SavetoworkspaceButton_2.ButtonPushedFcn = createCallbackFcn(app, @SavetoworkspaceButton_2Pushed, true);
            app.SavetoworkspaceButton_2.BackgroundColor = [1 1 1];
            app.SavetoworkspaceButton_2.Enable = 'off';
            app.SavetoworkspaceButton_2.Position = [160 27 129 22];
            app.SavetoworkspaceButton_2.Text = 'Save to workspace';

            % Create savevariantstrueCheckBox
            app.savevariantstrueCheckBox = uicheckbox(app.ResolutionVariantsPanel);
            app.savevariantstrueCheckBox.ValueChangedFcn = createCallbackFcn(app, @savevariantstrueCheckBoxValueChanged, true);
            app.savevariantstrueCheckBox.Enable = 'off';
            app.savevariantstrueCheckBox.Text = 'Variant indexation as [I_variants, M_variants]';
            app.savevariantstrueCheckBox.Position = [297 41 283 15];
            app.savevariantstrueCheckBox.Value = true;

            % Create saveORtrueCheckBox
            app.saveORtrueCheckBox = uicheckbox(app.ResolutionVariantsPanel);
            app.saveORtrueCheckBox.ValueChangedFcn = createCallbackFcn(app, @saveORtrueCheckBoxValueChanged, true);
            app.saveORtrueCheckBox.Enable = 'off';
            app.saveORtrueCheckBox.Text = 'Orientation relationship as fcc2bcc_rec';
            app.saveORtrueCheckBox.Position = [297 20 235 15];
            app.saveORtrueCheckBox.Value = true;

            % Create ResolutionVariantsPanel_3
            app.ResolutionVariantsPanel_3 = uipanel(app.MCLAnalysisTab);
            app.ResolutionVariantsPanel_3.Title = 'Reconstruction quality';
            app.ResolutionVariantsPanel_3.Position = [1 354 587 101];

            % Create PlotgrainbygrainButton
            app.PlotgrainbygrainButton = uibutton(app.ResolutionVariantsPanel_3, 'push');
            app.PlotgrainbygrainButton.ButtonPushedFcn = createCallbackFcn(app, @PlotgrainbygrainButtonPushed, true);
            app.PlotgrainbygrainButton.BackgroundColor = [1 1 1];
            app.PlotgrainbygrainButton.Enable = 'off';
            app.PlotgrainbygrainButton.Position = [12 23 129 22];
            app.PlotgrainbygrainButton.Text = 'Plot grain by grain';

            % Create recevaluationLabel
            app.recevaluationLabel = uilabel(app.ResolutionVariantsPanel_3);
            app.recevaluationLabel.Enable = 'off';
            app.recevaluationLabel.Position = [12 59 564 15];
            app.recevaluationLabel.Text = '';

            % Create SavetoworkspaceButton_3
            app.SavetoworkspaceButton_3 = uibutton(app.ResolutionVariantsPanel_3, 'push');
            app.SavetoworkspaceButton_3.ButtonPushedFcn = createCallbackFcn(app, @SavetoworkspaceButton_3Pushed, true);
            app.SavetoworkspaceButton_3.Enable = 'off';
            app.SavetoworkspaceButton_3.Position = [160 23 129 22];
            app.SavetoworkspaceButton_3.Text = 'Save to workspace';

            % Create graindeviationvaluesasdevisLabel
            app.graindeviationvaluesasdevisLabel = uilabel(app.ResolutionVariantsPanel_3);
            app.graindeviationvaluesasdevisLabel.Enable = 'off';
            app.graindeviationvaluesasdevisLabel.Position = [303 27 173 15];
            app.graindeviationvaluesasdevisLabel.Text = 'grain deviation values as devis';

            % Create PAGSviatriplepointsTab
            app.PAGSviatriplepointsTab = uitab(app.TabGroup);
            app.PAGSviatriplepointsTab.Title = 'PAGS via triple points';

            % Create OrientationrelationshipdeterminationPanel_2
            app.OrientationrelationshipdeterminationPanel_2 = uipanel(app.PAGSviatriplepointsTab);
            app.OrientationrelationshipdeterminationPanel_2.Title = 'Orientation relationship determination and partial reconstruction';
            app.OrientationrelationshipdeterminationPanel_2.Position = [0 373 640 82];

            % Create TriplepointORButton
            app.TriplepointORButton = uibutton(app.OrientationrelationshipdeterminationPanel_2, 'push');
            app.TriplepointORButton.ButtonPushedFcn = createCallbackFcn(app, @TriplepointORButtonPushed, true);
            app.TriplepointORButton.BackgroundColor = [1 1 1];
            app.TriplepointORButton.Enable = 'off';
            app.TriplepointORButton.Position = [16 27 129 22];
            app.TriplepointORButton.Text = 'Determine OR';

            % Create TriplepointdevelopmentCheckBox
            app.TriplepointdevelopmentCheckBox = uicheckbox(app.OrientationrelationshipdeterminationPanel_2);
            app.TriplepointdevelopmentCheckBox.Enable = 'off';
            app.TriplepointdevelopmentCheckBox.Text = 'view development';
            app.TriplepointdevelopmentCheckBox.Position = [18 11 127 15];
            app.TriplepointdevelopmentCheckBox.Value = true;

            % Create AusMisoPairsButton
            app.AusMisoPairsButton = uibutton(app.OrientationrelationshipdeterminationPanel_2, 'push');
            app.AusMisoPairsButton.ButtonPushedFcn = createCallbackFcn(app, @AusMisoPairsButtonPushed, true);
            app.AusMisoPairsButton.BackgroundColor = [1 1 1];
            app.AusMisoPairsButton.Enable = 'off';
            app.AusMisoPairsButton.Position = [164 27 129 22];
            app.AusMisoPairsButton.Text = 'Reconstruct';

            % Create PlottingandsavingPanel
            app.PlottingandsavingPanel = uipanel(app.PAGSviatriplepointsTab);
            app.PlottingandsavingPanel.Title = 'Plotting and saving';
            app.PlottingandsavingPanel.Position = [0 74 640 300];

            % Create AusTriplePointSave
            app.AusTriplePointSave = uibutton(app.PlottingandsavingPanel, 'push');
            app.AusTriplePointSave.ButtonPushedFcn = createCallbackFcn(app, @AusTriplePointSaveButtonPushed, true);
            app.AusTriplePointSave.BackgroundColor = [1 1 1];
            app.AusTriplePointSave.Enable = 'off';
            app.AusTriplePointSave.Position = [303 126 129 22];
            app.AusTriplePointSave.Text = 'Save';

            % Create TriplepointSaveFcc2bccCheckBox
            app.TriplepointSaveFcc2bccCheckBox = uicheckbox(app.PlottingandsavingPanel);
            app.TriplepointSaveFcc2bccCheckBox.Enable = 'off';
            app.TriplepointSaveFcc2bccCheckBox.Text = 'orientation relationship as fcc2bcc';
            app.TriplepointSaveFcc2bccCheckBox.Position = [303 208 208 15];
            app.TriplepointSaveFcc2bccCheckBox.Value = true;

            % Create TriplepointSaveVariantsHistCheckBox
            app.TriplepointSaveVariantsHistCheckBox = uicheckbox(app.PlottingandsavingPanel);
            app.TriplepointSaveVariantsHistCheckBox.Enable = 'off';
            app.TriplepointSaveVariantsHistCheckBox.Text = 'variant histogram as [variants_hist, variants_bin]';
            app.TriplepointSaveVariantsHistCheckBox.Position = [303 190 286 15];
            app.TriplepointSaveVariantsHistCheckBox.Value = true;

            % Create ExplainSaveLabel_4
            app.ExplainSaveLabel_4 = uilabel(app.PlottingandsavingPanel);
            app.ExplainSaveLabel_4.Enable = 'off';
            app.ExplainSaveLabel_4.Position = [303 229 108 15];
            app.ExplainSaveLabel_4.Text = 'Save to workspace';

            % Create TriplepointSaveFcc2bccCheckBox_2
            app.TriplepointSaveFcc2bccCheckBox_2 = uicheckbox(app.PlottingandsavingPanel);
            app.TriplepointSaveFcc2bccCheckBox_2.Enable = 'off';
            app.TriplepointSaveFcc2bccCheckBox_2.Text = 'Pair-based austenite orientation map as ebsd_aus_p';
            app.TriplepointSaveFcc2bccCheckBox_2.Position = [303 172 314 15];
            app.TriplepointSaveFcc2bccCheckBox_2.Value = true;

            % Create TriplepointSaveFcc2bccCheckBox_3
            app.TriplepointSaveFcc2bccCheckBox_3 = uicheckbox(app.PlottingandsavingPanel);
            app.TriplepointSaveFcc2bccCheckBox_3.Enable = 'off';
            app.TriplepointSaveFcc2bccCheckBox_3.Text = 'Triple point austenite orientation map as ebsd_aus_triple';
            app.TriplepointSaveFcc2bccCheckBox_3.Position = [303 153 336 15];
            app.TriplepointSaveFcc2bccCheckBox_3.Value = true;

            % Create TriplePointPlotButton
            app.TriplePointPlotButton = uibutton(app.PlottingandsavingPanel, 'push');
            app.TriplePointPlotButton.ButtonPushedFcn = createCallbackFcn(app, @TriplePointPlotButtonPushed, true);
            app.TriplePointPlotButton.BackgroundColor = [1 1 1];
            app.TriplePointPlotButton.Enable = 'off';
            app.TriplePointPlotButton.Position = [26 248 100 22];
            app.TriplePointPlotButton.Text = 'Plot map';

            % Create PlottingoptionsButtonGroup
            app.PlottingoptionsButtonGroup = uibuttongroup(app.PlottingandsavingPanel);
            app.PlottingoptionsButtonGroup.Title = 'Plotting options';
            app.PlottingoptionsButtonGroup.Position = [18 117 249 106];

            % Create BandcontrastonlyButton
            app.BandcontrastonlyButton = uiradiobutton(app.PlottingoptionsButtonGroup);
            app.BandcontrastonlyButton.Enable = 'off';
            app.BandcontrastonlyButton.Text = 'Band contrast only';
            app.BandcontrastonlyButton.Position = [11 60 123 15];

            % Create AusteniteindividualmisorientationpairsButton
            app.AusteniteindividualmisorientationpairsButton = uiradiobutton(app.PlottingoptionsButtonGroup);
            app.AusteniteindividualmisorientationpairsButton.Enable = 'off';
            app.AusteniteindividualmisorientationpairsButton.Text = 'Austenite, individual misorientation pairs';
            app.AusteniteindividualmisorientationpairsButton.Position = [10 38 244 15];
            app.AusteniteindividualmisorientationpairsButton.Value = true;

            % Create AustenitetriplepointsButton
            app.AustenitetriplepointsButton = uiradiobutton(app.PlottingoptionsButtonGroup);
            app.AustenitetriplepointsButton.Enable = 'off';
            app.AustenitetriplepointsButton.Text = 'Austenite, triple points';
            app.AustenitetriplepointsButton.Position = [11 16 142 15];

            % Create BoundaryoptionsButtonGroup
            app.BoundaryoptionsButtonGroup = uibuttongroup(app.PlottingandsavingPanel);
            app.BoundaryoptionsButtonGroup.Title = 'Boundary options';
            app.BoundaryoptionsButtonGroup.Position = [18 12 249 106];

            % Create BlocksButton
            app.BlocksButton = uiradiobutton(app.BoundaryoptionsButtonGroup);
            app.BlocksButton.Enable = 'off';
            app.BlocksButton.Text = 'Blocks';
            app.BlocksButton.Position = [11 60 168 15];

            % Create PacketsButton
            app.PacketsButton = uiradiobutton(app.BoundaryoptionsButtonGroup);
            app.PacketsButton.Enable = 'off';
            app.PacketsButton.Text = 'Packets';
            app.PacketsButton.Position = [10 38 65 15];

            % Create PAGSButton
            app.PAGSButton = uiradiobutton(app.BoundaryoptionsButtonGroup);
            app.PAGSButton.Enable = 'off';
            app.PAGSButton.Text = 'PAGS';
            app.PAGSButton.Position = [11 16 54 15];
            app.PAGSButton.Value = true;

            % Create NoBandContrastCheckBox
            app.NoBandContrastCheckBox = uicheckbox(app.PlottingandsavingPanel);
            app.NoBandContrastCheckBox.Enable = 'off';
            app.NoBandContrastCheckBox.Text = 'White background';
            app.NoBandContrastCheckBox.Position = [26 229 121 15];
        end
    end

    methods (Access = public)

        % Construct app
        function app = PAG_GUI

            % Create and configure 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