classdef AppTEST < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                matlab.ui.Figure                   % UI Figure
        LabelEditField          matlab.ui.control.Label            % Subjec...
        Initials                matlab.ui.control.EditField        % XX
        TabGroup                matlab.ui.container.TabGroup       % HFP, C...
        Tab_HFP                 matlab.ui.container.Tab            % HFP
        HFP_Pair_Sel            matlab.ui.container.Panel          % HFP Co...
        CheckBG                 matlab.ui.control.CheckBox         % B/G
        CheckRG                 matlab.ui.control.CheckBox         % R/G
        CheckBR                 matlab.ui.control.CheckBox         % B/R
        Label8                  matlab.ui.control.Label            % Pairs ...
        RunHFP                  matlab.ui.control.Button           % Run
        StopHFP                 matlab.ui.control.Button           % Stop
        Tab_Col_Disp            matlab.ui.container.Tab            % Color ...
        DisplayColor            matlab.ui.control.Button           % Display 
        Butt_Group_Disp_Select  matlab.ui.container.ButtonGroup    % Color ...
        Button_Subj_ratios      matlab.ui.control.RadioButton      % Subjec...
        Button_Custom_ratios    matlab.ui.control.RadioButton      % Custom
        Button_McLB_EEW         matlab.ui.control.RadioButton      % Mc Leo...
        Label13                 matlab.ui.control.Label            % R/G ratio
        Field_RG_Ratio          matlab.ui.control.NumericEditField % [-Inf ...
        Label14                 matlab.ui.control.Label            % B/G ratio
        Field_BG_Ratio          matlab.ui.control.NumericEditField % [-Inf ...
        Label15                 matlab.ui.control.Label            % L/(L+M)
        CD_littleL_Field        matlab.ui.control.NumericEditField % [-Inf ...
        Label16                 matlab.ui.control.Label            % S/(L+M)
        CD_littleS_Field        matlab.ui.control.NumericEditField % [-Inf ...
        Label17                 matlab.ui.control.Label            % Chroma...
        Label18                 matlab.ui.control.Label            % RGB ra...
        Update_RGB_Button       matlab.ui.control.Button           % Update...
        Update_Chromat_Button   matlab.ui.control.Button           % Update...
        Tab_ContMatch           matlab.ui.container.Tab            % Contra...
        PanelContMatch          matlab.ui.container.Panel          % Condit...
        Label3                  matlab.ui.control.Label            % C1
        NumericEditField6       matlab.ui.control.NumericEditField % [-Inf ...
        Label4                  matlab.ui.control.Label            % C3
        NumericEditField7       matlab.ui.control.NumericEditField % [-Inf ...
        Label5                  matlab.ui.control.Label            % C2
        NumericEditField8       matlab.ui.control.NumericEditField % [-Inf ...
        Label6                  matlab.ui.control.Label            % C4
        NumericEditField9       matlab.ui.control.NumericEditField % [-Inf ...
        Check_l_axis            matlab.ui.control.CheckBox         % Match ...
        Check_lum_axis          matlab.ui.control.CheckBox         % Match ...
        Label7                  matlab.ui.control.Label            % s_Cont...
        RunContMatch            matlab.ui.control.Button           % Run
        StopContMatch           matlab.ui.control.Button           % Stop
        Tab_ZaidiParad          matlab.ui.container.Tab            % Zaidi ...
        Panel                   matlab.ui.container.Panel          % Experi...
        LabelNumericEditField   matlab.ui.control.Label            % N repe...
        Repet_Field             matlab.ui.control.NumericEditField % [-Inf ...
        CheckBox                matlab.ui.control.CheckBox         % l_para...
        CheckBox2               matlab.ui.control.CheckBox         % s_para...
        CheckBox3               matlab.ui.control.CheckBox         % l_s_45°
        CheckBox4               matlab.ui.control.CheckBox         % l_s_135°
        CheckBox5               matlab.ui.control.CheckBox         % lum_pa...
        CheckBox6               matlab.ui.control.CheckBox         % lum_l_45°
        CheckBox7               matlab.ui.control.CheckBox         % lum_s_45°
        CheckBox8               matlab.ui.control.CheckBox         % lum_s_...
        CheckBox9               matlab.ui.control.CheckBox         % lum_l_...
        Run                     matlab.ui.control.Button           % Run Ex...
        Stop                    matlab.ui.control.Button           % Stop E...
        LabelNumericEditField10 matlab.ui.control.Label            % L/(L+M)
        littleL_Field           matlab.ui.control.NumericEditField % [-Inf ...
        Label9                  matlab.ui.control.Label            % S/(L+M)
        littleS_Field           matlab.ui.control.NumericEditField % [-Inf ...
        Label10                 matlab.ui.control.Label            % Backgr...
        Label11                 matlab.ui.control.Label            % Axis t...
        Load_Exp                matlab.ui.control.Button           % Load 
        Custom_Exp              matlab.ui.control.Button           % Custom 
        Label12                 matlab.ui.control.Label            % Lumina...
        Lum_Field               matlab.ui.control.NumericEditField % [-Inf ...
        Default_Exp             matlab.ui.control.Button           % Default 
    end

    methods (Access = private)

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

        % Initials value changed function
        function Initials_Changed(app)
            subName = app.Initials.Value;
            subName = upper(subName);
            
            
        aa = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/A Outputs');
        
        name = sprintf('%sHFP.mat', subName);
        if exist(name, 'file') == 2
        load(name)
        app.Field_RG_Ratio.Value = rg_avg
        app.Field_BG_Ratio.Value = bg_avg
        Update_Chromat_Pushed(app);
        else
        app.Field_RG_Ratio.Value = 0;
        app.Field_BG_Ratio.Value = 0
        Update_Chromat_Pushed(app);
                     
        end
        end

        % RunHFP button pushed function
        function Run_HFP_Push(app)
subName =  app.Initials.Value;
subName = upper(subName);

BG_check = app.CheckBG.Value;
RG_check = app.CheckRG.Value;
BR_check = app.CheckBR.Value;

curr_cond = [];
if BG_check ; curr_cond = [curr_cond; BG_check] ;end
if RG_check;  curr_cond = [curr_cond; RG_check] ;end
if BR_check; curr_cond = [curr_cond; BR_check] ;end

app.RunHFP.Enable = 'off';  app.StopHFP.Enable = 'on';

HFP_session(subName, curr_cond)

app.RunHFP.Enable = 'on';    app.StopHFP.Enable = 'off';


        end

        % RunContMatch button pushed function
        function Run_ContMatch_Push(app)
subName =  app.Initials.Value
subName = upper(subName);
l_axis_check = app.Check_l_axis.Value;
lum_axis_check = app.Check_lum_axis.Value;

curr_cond = [];
if l_axis_check ; curr_cond = [curr_cond; l_axis_check] ;end
if lum_axis_check;  curr_cond = [curr_cond; lum_axis_check] ;end

app.RunContMatch.Enable = 'off';  app.StopContMatch.Enable = 'on';

ContMatch_session(subName,curr_cond)

app.RunContMatch.Enable = 'on';    app.StopContMatch.Enable = 'off';


        end

        % DisplayColor button pushed function
        function DisplayColor_Pushed(app)

hfpRG = app.Field_RG_Ratio.Value 
hfpBG = app.Field_BG_Ratio.Value 

Disp_Color(hfpRG,hfpBG)


        end

        % Butt_Group_Disp_Select selection change function
        function ColDisp_Select_Changed(app, event)
selectedButton = app.Butt_Group_Disp_Select.SelectedObject
subName =  app.Initials.Value;
subName = upper(subName);


curr_Col_Sel = app.Butt_Group_Disp_Select.SelectedObject.Text

switch curr_Col_Sel
    case 'Subject chromaticities'
        
        aa = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/A Outputs');
        hfpFile = sprintf('%sHFP', subName);
        load(hfpFile, '-mat')
        app.Field_RG_Ratio.Value = rg_avg
        app.Field_BG_Ratio.Value = bg_avg
        app.Field_RG_Ratio.Editable = 'off';
        app.Field_BG_Ratio.Editable = 'off';
        app.Field_RG_Ratio.Enable = 'off';
        app.Field_BG_Ratio.Enable = 'off';
        
        
        
    case 'Custom'
        
        app.Field_RG_Ratio.Value = .7
        app.Field_BG_Ratio.Value = .7
        app.Field_RG_Ratio.Editable = 'on';
        app.Field_BG_Ratio.Editable = 'on';
        app.Field_RG_Ratio.Enable = 'on';
        app.Field_BG_Ratio.Enable = 'on';
        app.CD_littleL_Field.Editable = 'on'; 
        app.CD_littleS_Field.Editable = 'on'; 
        app.CD_littleL_Field.Enable = 'on'; 
        app.CD_littleS_Field.Enable = 'on'; 
        app.Update_RGB_Button.Enable = 'on';
        app.Update_Chromat_Button.Enable = 'on';
        
    case 'Mc Leod&Boynton EEW'
        
        aa = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/A Outputs');
        hfpFile = sprintf('%sHFP', subName);
        load(hfpFile, '-mat')
        app.Field_RG_Ratio.Value = 1
        app.Field_BG_Ratio.Value = 1
        app.Field_RG_Ratio.Editable = 'off';
        app.Field_BG_Ratio.Editable = 'off';
        app.Field_RG_Ratio.Enable = 'off';
        app.Field_BG_Ratio.Enable = 'off';

        
end
     
        end

        % Run button pushed function
        function Run_Exp_Pushed(app)
app.Run.Enable = 'off';                    
subName =  app.Initials.Value;
NumRep = app.Repet_Field.Value;
maxLum = app.Lum_Field.Value; 
white = [app.littleL_Field.Value  app.littleS_Field.Value];

l_check = app.CheckBox.Value;
s_check = app.CheckBox2.Value;
ls45_check = app.CheckBox3.Value;
ls135_check = app.CheckBox4.Value;
lum_check = app.CheckBox5.Value;
lum_l_45_check = app.CheckBox6.Value;
lum_l_135_check = app.CheckBox7.Value;
lum_s_45_check = app.CheckBox8.Value;
lum_s_135_check = app.CheckBox9.Value;



l_idx = 1
s_idx = 2;
ls45_idx = 3;
ls135_idx = 4;
lum_idx = 5;
lum_l_45_idx = 6;
lum_l_135_idx = 7;
lum_s_45_idx = 8;
lum_s_135_idx = 9;

curr_cond = [];
if l_check ; curr_cond = [curr_cond; l_idx] ;end
if s_check;  curr_cond = [curr_cond; s_idx] ;end
if ls45_check; curr_cond = [curr_cond; ls45_idx] ;end
if ls135_check ; curr_cond = [curr_cond; ls135_idx] ;end
if lum_check;  curr_cond = [curr_cond; lum_idx] ;end
if lum_l_45_check; curr_cond = [curr_cond; lum_l_45_idx] ;end
if lum_l_135_check ; curr_cond = [curr_cond; lum_l_135_idx] ;end
if lum_s_45_check;  curr_cond = [curr_cond; lum_s_45_idx] ;end
if lum_s_135_check; curr_cond = [curr_cond; lum_s_135_idx] ;end

    
numRep = app.Repet_Field.Value;
    
saveFile = sprintf('%s_afterimage', subName)

AfIm_Exp(subName,numRep,maxLum,white,curr_cond);



app.Run.Enable = 'on';
app.Stop.Enable = 'off';
%create a matrix of seconds compared to pi values for each frame - just
%used in data analysis
% piVSsecs(:,1) = [0:1/(nFrames-1):1];
% piVSsecs(:,2) = [0:numSecs/(nFrames-1):numSecs];

   
        end

        % Field_BG_Ratio value changed function
        function Field_BG_ratio_Changed(app)
            value = app.Field_BG_Ratio.Value;
            
        end

        % Stop button pushed function
        function Stop_Pushed(app)
            Screen('CloseAll')
            sca;
            app.Run.Enable = 'on';
            app.Stop.Enable = 'off';
        end

        % Repet_Field value changed function
        function NRepetitions_Changed(app)
            NumRep = app.Repet_Field.Value;
            
        end

        % NumericEditField6 value changed function
        function C1_Changed(app)
            s_C1 = app.NumericEditField6.Value;
            
        end

        % Custom_Exp button pushed function
        function Custom_Exp_Pushed(app)

app.CheckBox.Enable = 'on';
app.CheckBox2.Enable = 'on';
app.CheckBox3.Enable = 'on';
app.CheckBox4.Enable = 'on';
app.CheckBox5.Enable = 'on';
app.CheckBox6.Enable = 'on';
app.CheckBox7.Enable = 'on';
app.CheckBox8.Enable = 'on';
app.CheckBox9.Enable = 'on';
app.Repet_Field.Enable = 'on'; app.Repet_Field.Editable = 'on';
app.Lum_Field.Enable = 'on'; app.Lum_Field.Editable = 'on';
app.littleL_Field.Enable = 'on'; app.littleL_Field.Editable = 'on';
app.littleS_Field.Enable = 'on'; app.littleS_Field.Editable = 'on';


        end

        % Default_Exp button pushed function
        function Default_Exp_Pushed(app)
app.CheckBox.Value = true;
app.CheckBox2.Value = true;
app.CheckBox3.Value = true;
app.CheckBox4.Value = true;
app.CheckBox5.Value = true;
app.CheckBox6.Value = true;
app.CheckBox7.Value = true;
app.CheckBox8.Value = true;
app.CheckBox9.Value = true;
app.Repet_Field.Value = 3;
app.Lum_Field.Value = 20; 
app.littleL_Field.Value = 0.665; 
app.littleS_Field.Value = 1;  
        end

        % Load_Exp button pushed function
        function Load_Exp_Pushed(app)
[FileName,PathName] = uigetfile('*.txt','Select the MATLAB code file');

% if isempty(FileMane)% is I press cancel it does not fail

Data = readtable(FileName)

Values = Data.Values;
app.Lum_Field.Value = str2num(Values{1}); 
app.littleL_Field.Value = str2num(Values{2}); 
app.littleS_Field.Value = str2num(Values{3});
app.CheckBox.Value = str2num(Values{4});
app.CheckBox2.Value = str2num(Values{5});
app.CheckBox3.Value = str2num(Values{6});
app.CheckBox4.Value = str2num(Values{7});
app.CheckBox5.Value = str2num(Values{8});
app.CheckBox6.Value = str2num(Values{9});
app.CheckBox7.Value = str2num(Values{10});
app.CheckBox8.Value = str2num(Values{11});
app.CheckBox9.Value = str2num(Values{12});
app.Repet_Field.Value = str2num(Values{13});
        end

        % Update_RGB_Button button pushed function
        function Update_RGB_Pushed(app)
            curr_l = app.CD_littleL_Field.Value;
            curr_s = app.CD_littleS_Field.Value;
            maxLum = 20;
            
load colorCalFile1.mat
fprintf('\nLast calibration was %s\n', describe.date);
pix = pix/1001;
            
% LMS to XYZ
wLMS(1,1) = curr_l*maxLum;
wLMS(1,2) = (1-curr_l)*maxLum;
wLMS(1,3) = curr_s*maxLum;
wXYZ(1,:) = LMS_to_XYZ(wLMS(1,:));
% XYZ to  RGB
wRGB(1,:) = XYZ_to_RGB(wXYZ(1,:), maxPhosXYZ);
wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)));
wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2)));
wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)));

            % RATIOS
            rg_ratio = wRGB(1,1)/wRGB(1,2);
            bg_ratio = wRGB(1,3)/wRGB(1,2);
            
            app.Field_RG_Ratio.Value = rg_ratio;
            app.Field_BG_Ratio.Value = bg_ratio;
        end

        % Update_Chromat_Button button pushed function
        function Update_Chromat_Pushed(app)
            curr_RG_Ratio = app.Field_RG_Ratio.Value;
            curr_BG_Ratio = app.Field_BG_Ratio.Value;
            
load colorCalFile1.mat
fprintf('\nLast calibration was %s\n', describe.date);
pix = pix/1001;

% RGB to XYZ

wLMS(1,1) = white(1,1)*maxLum;
wLMS(1,2) = (1-white(1,1))*maxLum;
wLMS(1,3) = white(1,2)*maxLum;
wXYZ(1,:) = LMS_to_XYZ(wLMS(1,:));
wRGB(1,:) = XYZ_to_RGB(wXYZ(1,:), maxPhosXYZ);
wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)))*hfpRG;
wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2)));
wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)))*hfpBG;


wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)))*curr_RG_Ratio;
wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2)));
wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)))*curr_BG_Ratio;

            

            % RATIOS
            app.CD_littleL.Value = 'NaN';
            app.CD_littleS.Value = 'NaN';
        end

        % StopHFP button pushed function
        function StopHFP_Pushed(app)
%             drawnow
            return
            Screen('CloseAll')
            sca;
            app.RunHFP.Enable = 'on';
            app.StopHFP.Enable = 'off';
        end

        % StopContMatch button pushed function
        function StopContMatch_Pushed(app)
            Screen('CloseAll')
            sca;
            app.RunContMatch.Enable = 'on';
            app.StopContMatch.Enable = 'off';
        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 653 493];
            app.UIFigure.Name = 'UI Figure';
            setAutoResize(app, app.UIFigure, true)

            % Create LabelEditField
            app.LabelEditField = uilabel(app.UIFigure);
            app.LabelEditField.HorizontalAlignment = 'right';
            app.LabelEditField.Position = [12.03125 443 79 15];
            app.LabelEditField.Text = 'Subject Initials';

            % Create Initials
            app.Initials = uieditfield(app.UIFigure, 'text');
            app.Initials.ValueChangedFcn = createCallbackFcn(app, @Initials_Changed);
            app.Initials.Position = [106.03125 439 100 22];
            app.Initials.Value = 'XX';

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Units = 'pixels';
            app.TabGroup.Position = [12 46 618 374];

            % Create Tab_HFP
            app.Tab_HFP = uitab(app.TabGroup);
            app.Tab_HFP.Units = 'pixels';
            app.Tab_HFP.Title = 'HFP';

            % Create HFP_Pair_Sel
            app.HFP_Pair_Sel = uipanel(app.Tab_HFP);
            app.HFP_Pair_Sel.BorderType = 'line';
            app.HFP_Pair_Sel.Title = 'HFP Conditions';
            app.HFP_Pair_Sel.FontWeight = 'bold';
            app.HFP_Pair_Sel.FontUnits = 'pixels';
            app.HFP_Pair_Sel.FontSize = 12;
            app.HFP_Pair_Sel.Units = 'pixels';
            app.HFP_Pair_Sel.Position = [17 211 583 127];

            % Create CheckBG
            app.CheckBG = uicheckbox(app.HFP_Pair_Sel);
            app.CheckBG.Enable = 'off';
            app.CheckBG.Text = 'B/G';
            app.CheckBG.Position = [8 57 40.328125 16];
            app.CheckBG.Value = true;

            % Create CheckRG
            app.CheckRG = uicheckbox(app.HFP_Pair_Sel);
            app.CheckRG.Enable = 'off';
            app.CheckRG.Text = 'R/G';
            app.CheckRG.Position = [8 34 40.328125 16];
            app.CheckRG.Value = true;

            % Create CheckBR
            app.CheckBR = uicheckbox(app.HFP_Pair_Sel);
            app.CheckBR.Enable = 'off';
            app.CheckBR.Text = 'B/R';
            app.CheckBR.Position = [9 12 39.4375 16];
            app.CheckBR.Value = true;

            % Create Label8
            app.Label8 = uilabel(app.HFP_Pair_Sel);
            app.Label8.FontWeight = 'bold';
            app.Label8.FontAngle = 'italic';
            app.Label8.Position = [8 83 87 15];
            app.Label8.Text = 'Pairs to match:';

            % Create RunHFP
            app.RunHFP = uibutton(app.HFP_Pair_Sel, 'push');
            app.RunHFP.ButtonPushedFcn = createCallbackFcn(app, @Run_HFP_Push);
            app.RunHFP.Position = [428 42 141 41];
            app.RunHFP.Text = 'Run';

            % Create StopHFP
            app.StopHFP = uibutton(app.HFP_Pair_Sel, 'push');
            app.StopHFP.ButtonPushedFcn = createCallbackFcn(app, @StopHFP_Pushed);
            app.StopHFP.Enable = 'off';
            app.StopHFP.Position = [428 8 141 28];
            app.StopHFP.Text = 'Stop';

            % Create Tab_Col_Disp
            app.Tab_Col_Disp = uitab(app.TabGroup);
            app.Tab_Col_Disp.Units = 'pixels';
            app.Tab_Col_Disp.Title = 'Color Display';

            % Create DisplayColor
            app.DisplayColor = uibutton(app.Tab_Col_Disp, 'push');
            app.DisplayColor.ButtonPushedFcn = createCallbackFcn(app, @DisplayColor_Pushed);
            app.DisplayColor.Position = [250.96875 24 143 44];
            app.DisplayColor.Text = 'Display ';

            % Create Butt_Group_Disp_Select
            app.Butt_Group_Disp_Select = uibuttongroup(app.Tab_Col_Disp);
            app.Butt_Group_Disp_Select.SelectionChangedFcn = createCallbackFcn(app, @ColDisp_Select_Changed, true);
            app.Butt_Group_Disp_Select.BorderType = 'none';
            app.Butt_Group_Disp_Select.Title = 'Color Selection';
            app.Butt_Group_Disp_Select.FontUnits = 'pixels';
            app.Butt_Group_Disp_Select.FontSize = 12;
            app.Butt_Group_Disp_Select.Units = 'pixels';
            app.Butt_Group_Disp_Select.Position = [16 235 188 106];

            % Create Button_Subj_ratios
            app.Button_Subj_ratios = uiradiobutton(app.Butt_Group_Disp_Select);
            app.Button_Subj_ratios.Text = 'Subject chromaticities';
            app.Button_Subj_ratios.Position = [10 60 138.359375 16];
            app.Button_Subj_ratios.Value = true;

            % Create Button_Custom_ratios
            app.Button_Custom_ratios = uiradiobutton(app.Butt_Group_Disp_Select);
            app.Button_Custom_ratios.Text = 'Custom';
            app.Button_Custom_ratios.Position = [10 38 61.25 16];

            % Create Button_McLB_EEW
            app.Button_McLB_EEW = uiradiobutton(app.Butt_Group_Disp_Select);
            app.Button_McLB_EEW.Text = 'Mc Leod&Boynton EEW';
            app.Button_McLB_EEW.Position = [10 16 148.15625 16];

            % Create Label13
            app.Label13 = uilabel(app.Tab_Col_Disp);
            app.Label13.Enable = 'off';
            app.Label13.HorizontalAlignment = 'right';
            app.Label13.Position = [367 180 49 15];
            app.Label13.Text = 'R/G ratio';

            % Create Field_RG_Ratio
            app.Field_RG_Ratio = uieditfield(app.Tab_Col_Disp, 'numeric');
            app.Field_RG_Ratio.Enable = 'off';
            app.Field_RG_Ratio.Editable = 'off';
            app.Field_RG_Ratio.Position = [431 176 44 22];
            app.Field_RG_Ratio.Value = 1;

            % Create Label14
            app.Label14 = uilabel(app.Tab_Col_Disp);
            app.Label14.Enable = 'off';
            app.Label14.HorizontalAlignment = 'right';
            app.Label14.Position = [367 141 49 15];
            app.Label14.Text = 'B/G ratio';

            % Create Field_BG_Ratio
            app.Field_BG_Ratio = uieditfield(app.Tab_Col_Disp, 'numeric');
            app.Field_BG_Ratio.Enable = 'off';
            app.Field_BG_Ratio.Editable = 'off';
            app.Field_BG_Ratio.Position = [431 137 44 22];
            app.Field_BG_Ratio.Value = 1;

            % Create Label15
            app.Label15 = uilabel(app.Tab_Col_Disp);
            app.Label15.Enable = 'off';
            app.Label15.HorizontalAlignment = 'right';
            app.Label15.Position = [166 180 42 15];
            app.Label15.Text = 'L/(L+M)';

            % Create CD_littleL_Field
            app.CD_littleL_Field = uieditfield(app.Tab_Col_Disp, 'numeric');
            app.CD_littleL_Field.Enable = 'off';
            app.CD_littleL_Field.Editable = 'off';
            app.CD_littleL_Field.Position = [215 176 44 22];
            app.CD_littleL_Field.Value = 0.665;

            % Create Label16
            app.Label16 = uilabel(app.Tab_Col_Disp);
            app.Label16.Enable = 'off';
            app.Label16.HorizontalAlignment = 'right';
            app.Label16.Position = [164 141 43 15];
            app.Label16.Text = 'S/(L+M)';

            % Create CD_littleS_Field
            app.CD_littleS_Field = uieditfield(app.Tab_Col_Disp, 'numeric');
            app.CD_littleS_Field.Enable = 'off';
            app.CD_littleS_Field.Editable = 'off';
            app.CD_littleS_Field.Position = [216 137 44 22];
            app.CD_littleS_Field.Value = 1;

            % Create Label17
            app.Label17 = uilabel(app.Tab_Col_Disp);
            app.Label17.FontWeight = 'bold';
            app.Label17.Position = [141 213 143 15];
            app.Label17.Text = 'Chromaticities (McL&B) :';

            % Create Label18
            app.Label18 = uilabel(app.Tab_Col_Disp);
            app.Label18.FontWeight = 'bold';
            app.Label18.Position = [392 213 63 15];
            app.Label18.Text = 'RGB ratios';

            % Create Update_RGB_Button
            app.Update_RGB_Button = uibutton(app.Tab_Col_Disp, 'push');
            app.Update_RGB_Button.ButtonPushedFcn = createCallbackFcn(app, @Update_RGB_Pushed);
            app.Update_RGB_Button.Enable = 'off';
            app.Update_RGB_Button.FontSize = 11;
            app.Update_RGB_Button.Position = [154.5 92 118 22];
            app.Update_RGB_Button.Text = 'Update RGB ratios';

            % Create Update_Chromat_Button
            app.Update_Chromat_Button = uibutton(app.Tab_Col_Disp, 'push');
            app.Update_Chromat_Button.ButtonPushedFcn = createCallbackFcn(app, @Update_Chromat_Pushed);
            app.Update_Chromat_Button.Enable = 'off';
            app.Update_Chromat_Button.FontSize = 11;
            app.Update_Chromat_Button.Position = [362 92 125 22];
            app.Update_Chromat_Button.Text = 'Update chromaticities';

            % Create Tab_ContMatch
            app.Tab_ContMatch = uitab(app.TabGroup);
            app.Tab_ContMatch.Units = 'pixels';
            app.Tab_ContMatch.Title = 'Contrast Matching';

            % Create PanelContMatch
            app.PanelContMatch = uipanel(app.Tab_ContMatch);
            app.PanelContMatch.BorderType = 'line';
            app.PanelContMatch.Title = 'Conditions';
            app.PanelContMatch.FontWeight = 'bold';
            app.PanelContMatch.FontUnits = 'pixels';
            app.PanelContMatch.FontSize = 12;
            app.PanelContMatch.Units = 'pixels';
            app.PanelContMatch.Position = [13 170 589 171];

            % Create Label3
            app.Label3 = uilabel(app.PanelContMatch);
            app.Label3.HorizontalAlignment = 'right';
            app.Label3.Position = [65.03125 101 20 15];
            app.Label3.Text = 'C1';

            % Create NumericEditField6
            app.NumericEditField6 = uieditfield(app.PanelContMatch, 'numeric');
            app.NumericEditField6.ValueChangedFcn = createCallbackFcn(app, @C1_Changed);
            app.NumericEditField6.Enable = 'off';
            app.NumericEditField6.Editable = 'off';
            app.NumericEditField6.Position = [100.03125 97 55 22];
            app.NumericEditField6.Value = 0.35;

            % Create Label4
            app.Label4 = uilabel(app.PanelContMatch);
            app.Label4.HorizontalAlignment = 'right';
            app.Label4.Position = [302.03125 101 20 15];
            app.Label4.Text = 'C3';

            % Create NumericEditField7
            app.NumericEditField7 = uieditfield(app.PanelContMatch, 'numeric');
            app.NumericEditField7.Enable = 'off';
            app.NumericEditField7.Editable = 'off';
            app.NumericEditField7.Position = [337.03125 97 55 22];
            app.NumericEditField7.Value = 0.65;

            % Create Label5
            app.Label5 = uilabel(app.PanelContMatch);
            app.Label5.HorizontalAlignment = 'right';
            app.Label5.Position = [182.03125 101 20 15];
            app.Label5.Text = 'C2';

            % Create NumericEditField8
            app.NumericEditField8 = uieditfield(app.PanelContMatch, 'numeric');
            app.NumericEditField8.Enable = 'off';
            app.NumericEditField8.Editable = 'off';
            app.NumericEditField8.Position = [217.03125 97 55 22];
            app.NumericEditField8.Value = 0.5;

            % Create Label6
            app.Label6 = uilabel(app.PanelContMatch);
            app.Label6.HorizontalAlignment = 'right';
            app.Label6.Position = [430.03125 101 20 15];
            app.Label6.Text = 'C4';

            % Create NumericEditField9
            app.NumericEditField9 = uieditfield(app.PanelContMatch, 'numeric');
            app.NumericEditField9.Enable = 'off';
            app.NumericEditField9.Editable = 'off';
            app.NumericEditField9.Position = [465.03125 97 55 22];
            app.NumericEditField9.Value = 0.8;

            % Create Check_l_axis
            app.Check_l_axis = uicheckbox(app.PanelContMatch);
            app.Check_l_axis.Enable = 'off';
            app.Check_l_axis.Text = 'Match l_axis contrasts';
            app.Check_l_axis.Position = [79 46 139.46875 16];
            app.Check_l_axis.Value = true;

            % Create Check_lum_axis
            app.Check_lum_axis = uicheckbox(app.PanelContMatch);
            app.Check_lum_axis.Enable = 'off';
            app.Check_lum_axis.Text = 'Match lum_axis contrasts';
            app.Check_lum_axis.Position = [79 23 156.375 16];
            app.Check_lum_axis.Value = true;

            % Create Label7
            app.Label7 = uilabel(app.PanelContMatch);
            app.Label7.FontWeight = 'bold';
            app.Label7.FontAngle = 'italic';
            app.Label7.Position = [71 126 121 15];
            app.Label7.Text = 's_Contrast to match:';

            % Create RunContMatch
            app.RunContMatch = uibutton(app.PanelContMatch, 'push');
            app.RunContMatch.ButtonPushedFcn = createCallbackFcn(app, @Run_ContMatch_Push);
            app.RunContMatch.Position = [449 38 129 41];
            app.RunContMatch.Text = 'Run';

            % Create StopContMatch
            app.StopContMatch = uibutton(app.PanelContMatch, 'push');
            app.StopContMatch.ButtonPushedFcn = createCallbackFcn(app, @StopContMatch_Pushed);
            app.StopContMatch.Enable = 'off';
            app.StopContMatch.Position = [451 5 127 28];
            app.StopContMatch.Text = 'Stop';

            % Create Tab_ZaidiParad
            app.Tab_ZaidiParad = uitab(app.TabGroup);
            app.Tab_ZaidiParad.Units = 'pixels';
            app.Tab_ZaidiParad.Title = 'Zaidi Paradigm';

            % Create Panel
            app.Panel = uipanel(app.Tab_ZaidiParad);
            app.Panel.BorderType = 'line';
            app.Panel.Title = 'Experiment Conditions';
            app.Panel.FontWeight = 'bold';
            app.Panel.FontUnits = 'pixels';
            app.Panel.FontSize = 12;
            app.Panel.Units = 'pixels';
            app.Panel.Position = [24 15 537 325];

            % Create LabelNumericEditField
            app.LabelNumericEditField = uilabel(app.Panel);
            app.LabelNumericEditField.HorizontalAlignment = 'right';
            app.LabelNumericEditField.FontWeight = 'bold';
            app.LabelNumericEditField.Position = [168.03125 113 74 15];
            app.LabelNumericEditField.Text = 'N repetitions';

            % Create Repet_Field
            app.Repet_Field = uieditfield(app.Panel, 'numeric');
            app.Repet_Field.ValueChangedFcn = createCallbackFcn(app, @NRepetitions_Changed);
            app.Repet_Field.Enable = 'off';
            app.Repet_Field.Editable = 'off';
            app.Repet_Field.Position = [257.03125 109 41 22];
            app.Repet_Field.Value = 3;

            % Create CheckBox
            app.CheckBox = uicheckbox(app.Panel);
            app.CheckBox.Enable = 'off';
            app.CheckBox.Text = 'l_parallel_axis';
            app.CheckBox.Position = [173 200 93.4375 16];
            app.CheckBox.Value = true;

            % Create CheckBox2
            app.CheckBox2 = uicheckbox(app.Panel);
            app.CheckBox2.Enable = 'off';
            app.CheckBox2.Text = 's_parallel_axis';
            app.CheckBox2.Position = [172 177 96.765625 16];
            app.CheckBox2.Value = true;

            % Create CheckBox3
            app.CheckBox3 = uicheckbox(app.Panel);
            app.CheckBox3.Enable = 'off';
            app.CheckBox3.Text = 'l_s_45°';
            app.CheckBox3.Position = [172 150 57.8125 16];
            app.CheckBox3.Value = true;

            % Create CheckBox4
            app.CheckBox4 = uicheckbox(app.Panel);
            app.CheckBox4.Enable = 'off';
            app.CheckBox4.Text = 'l_s_135°';
            app.CheckBox4.Position = [317 200 64.484375 16];
            app.CheckBox4.Value = true;

            % Create CheckBox5
            app.CheckBox5 = uicheckbox(app.Panel);
            app.CheckBox5.Enable = 'off';
            app.CheckBox5.Text = 'lum_parallel_axis';
            app.CheckBox5.Position = [317 177 110.34375 16];
            app.CheckBox5.Value = true;

            % Create CheckBox6
            app.CheckBox6 = uicheckbox(app.Panel);
            app.CheckBox6.Enable = 'off';
            app.CheckBox6.Text = 'lum_l_45°';
            app.CheckBox6.Position = [317 150 71.390625 16];
            app.CheckBox6.Value = true;

            % Create CheckBox7
            app.CheckBox7 = uicheckbox(app.Panel);
            app.CheckBox7.Enable = 'off';
            app.CheckBox7.Text = 'lum_s_45°';
            app.CheckBox7.Position = [444 177 74.71875 16];
            app.CheckBox7.Value = true;

            % Create CheckBox8
            app.CheckBox8 = uicheckbox(app.Panel);
            app.CheckBox8.Enable = 'off';
            app.CheckBox8.Text = 'lum_s_135°';
            app.CheckBox8.Position = [444 150 81.390625 16];
            app.CheckBox8.Value = true;

            % Create CheckBox9
            app.CheckBox9 = uicheckbox(app.Panel);
            app.CheckBox9.Enable = 'off';
            app.CheckBox9.Text = 'lum_l_135°';
            app.CheckBox9.Position = [444 200 78.0625 16];
            app.CheckBox9.Value = true;

            % Create Run
            app.Run = uibutton(app.Panel, 'push');
            app.Run.ButtonPushedFcn = createCallbackFcn(app, @Run_Exp_Pushed);
            app.Run.Position = [387 47 141 51];
            app.Run.Text = 'Run Experiment';

            % Create Stop
            app.Stop = uibutton(app.Panel, 'push');
            app.Stop.ButtonPushedFcn = createCallbackFcn(app, @Stop_Pushed);
            app.Stop.Enable = 'off';
            app.Stop.Position = [387 12 141 28];
            app.Stop.Text = 'Stop Experiment';

            % Create LabelNumericEditField10
            app.LabelNumericEditField10 = uilabel(app.Panel);
            app.LabelNumericEditField10.HorizontalAlignment = 'right';
            app.LabelNumericEditField10.Position = [315.03125 255 42 15];
            app.LabelNumericEditField10.Text = 'L/(L+M)';

            % Create littleL_Field
            app.littleL_Field = uieditfield(app.Panel, 'numeric');
            app.littleL_Field.Enable = 'off';
            app.littleL_Field.Editable = 'off';
            app.littleL_Field.Position = [364.03125 251 44 22];
            app.littleL_Field.Value = 0.665;

            % Create Label9
            app.Label9 = uilabel(app.Panel);
            app.Label9.HorizontalAlignment = 'right';
            app.Label9.Position = [422.03125 255 43 15];
            app.Label9.Text = 'S/(L+M)';

            % Create littleS_Field
            app.littleS_Field = uieditfield(app.Panel, 'numeric');
            app.littleS_Field.Enable = 'off';
            app.littleS_Field.Editable = 'off';
            app.littleS_Field.Position = [474.03125 251 44 22];
            app.littleS_Field.Value = 1;

            % Create Label10
            app.Label10 = uilabel(app.Panel);
            app.Label10.FontWeight = 'bold';
            app.Label10.Position = [249 284 214 15];
            app.Label10.Text = 'Background chromaticities (McL&B) :';

            % Create Label11
            app.Label11 = uilabel(app.Panel);
            app.Label11.FontWeight = 'bold';
            app.Label11.Position = [307 226 99 15];
            app.Label11.Text = 'Axis to stimulate:';

            % Create Load_Exp
            app.Load_Exp = uibutton(app.Panel, 'push');
            app.Load_Exp.ButtonPushedFcn = createCallbackFcn(app, @Load_Exp_Pushed);
            app.Load_Exp.Position = [7 271 105 22];
            app.Load_Exp.Text = 'Load ';

            % Create Custom_Exp
            app.Custom_Exp = uibutton(app.Panel, 'push');
            app.Custom_Exp.ButtonPushedFcn = createCallbackFcn(app, @Custom_Exp_Pushed);
            app.Custom_Exp.Position = [7 234 108 22];
            app.Custom_Exp.Text = 'Custom ';

            % Create Label12
            app.Label12 = uilabel(app.Panel);
            app.Label12.HorizontalAlignment = 'right';
            app.Label12.Position = [152.03125 255 103 15];
            app.Label12.Text = 'Luminance (cd/m2)';

            % Create Lum_Field
            app.Lum_Field = uieditfield(app.Panel, 'numeric');
            app.Lum_Field.Enable = 'off';
            app.Lum_Field.Editable = 'off';
            app.Lum_Field.Position = [265.03125 251 35 22];
            app.Lum_Field.Value = 20;

            % Create Default_Exp
            app.Default_Exp = uibutton(app.Panel, 'push');
            app.Default_Exp.ButtonPushedFcn = createCallbackFcn(app, @Default_Exp_Pushed);
            app.Default_Exp.Position = [7 195 108 22];
            app.Default_Exp.Text = 'Default ';
        end
    end

    methods (Access = public)

        % Construct app
        function app = AppTEST()

            % Create and configure components
            createComponents(app)

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

            % Execute the startup function
            runStartupFcn(app, @startupFcn)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end