classdef TVP_GENERATOR < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                 matlab.ui.Figure
        LabelEditField           matlab.ui.control.Label
        Initials                 matlab.ui.control.EditField
        TabGroup                 matlab.ui.container.TabGroup
        Tab_HFP                  matlab.ui.container.Tab
        HFP_Pair_Sel             matlab.ui.container.Panel
        CheckBG                  matlab.ui.control.CheckBox
        CheckRG                  matlab.ui.control.CheckBox
        CheckBR                  matlab.ui.control.CheckBox
        Label8                   matlab.ui.control.Label
        RunHFP                   matlab.ui.control.Button
        StopHFP                  matlab.ui.control.Button
        Tab_Col_Disp             matlab.ui.container.Tab
        DisplayColor             matlab.ui.control.Button
        Butt_Group_Disp_Select   matlab.ui.container.ButtonGroup
        Button_Subj_ratios       matlab.ui.control.RadioButton
        Button_Custom_ratios     matlab.ui.control.RadioButton
        Label13                  matlab.ui.control.Label
        Field_RG_Ratio           matlab.ui.control.NumericEditField
        Label14                  matlab.ui.control.Label
        Field_BG_Ratio           matlab.ui.control.NumericEditField
        Label15                  matlab.ui.control.Label
        CD_littleL_Field         matlab.ui.control.NumericEditField
        Label16                  matlab.ui.control.Label
        CD_littleS_Field         matlab.ui.control.NumericEditField
        Label17                  matlab.ui.control.Label
        Label18                  matlab.ui.control.Label
        Tab_ContMatch            matlab.ui.container.Tab
        PanelContMatch           matlab.ui.container.Panel
        Label3                   matlab.ui.control.Label
        NumericEditField6        matlab.ui.control.NumericEditField
        Label4                   matlab.ui.control.Label
        NumericEditField7        matlab.ui.control.NumericEditField
        Label5                   matlab.ui.control.Label
        NumericEditField8        matlab.ui.control.NumericEditField
        Label6                   matlab.ui.control.Label
        NumericEditField9        matlab.ui.control.NumericEditField
        Check_l_axis             matlab.ui.control.CheckBox
        Check_lum_axis           matlab.ui.control.CheckBox
        Label7                   matlab.ui.control.Label
        RunContMatch             matlab.ui.control.Button
        StopContMatch            matlab.ui.control.Button
        LoadContMatch            matlab.ui.control.Button
        FileNameContMatch        matlab.ui.control.EditField
        LabelEditField2          matlab.ui.control.Label
        Label20                  matlab.ui.control.Label
        AdaptContMatch           matlab.ui.control.NumericEditField
        Label21                  matlab.ui.control.Label
        LumContMatch             matlab.ui.control.NumericEditField
        Tab_ZaidiParad           matlab.ui.container.Tab
        Panel                    matlab.ui.container.Panel
        LabelNumericEditField    matlab.ui.control.Label
        RepetExp                 matlab.ui.control.NumericEditField
        CheckBox                 matlab.ui.control.CheckBox
        CheckBox2                matlab.ui.control.CheckBox
        CheckBox3                matlab.ui.control.CheckBox
        CheckBox4                matlab.ui.control.CheckBox
        CheckBox5                matlab.ui.control.CheckBox
        CheckBox6                matlab.ui.control.CheckBox
        CheckBox7                matlab.ui.control.CheckBox
        CheckBox8                matlab.ui.control.CheckBox
        CheckBox9                matlab.ui.control.CheckBox
        Run                      matlab.ui.control.Button
        Stop                     matlab.ui.control.Button
        LabelNumericEditField10  matlab.ui.control.Label
        littleL_Field            matlab.ui.control.NumericEditField
        Label9                   matlab.ui.control.Label
        littleS_Field            matlab.ui.control.NumericEditField
        Label10                  matlab.ui.control.Label
        Label11                  matlab.ui.control.Label
        Load_Exp                 matlab.ui.control.Button
        Custom_Exp               matlab.ui.control.Button
        Label12                  matlab.ui.control.Label
        Lum_Field                matlab.ui.control.NumericEditField
        Default_Exp              matlab.ui.control.Button
        Simulate                 matlab.ui.control.CheckBox
        Label19                  matlab.ui.control.Label
        AdaptTime                matlab.ui.control.NumericEditField
        FilenameExp              matlab.ui.control.EditField
        Label22                  matlab.ui.control.Label
        OneHemi                  matlab.ui.control.CheckBox
        Pupil                    matlab.ui.control.CheckBox
        OneEnd                   matlab.ui.control.CheckBox
    end

    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
% f=uifigure;
% t = uitable(f)
% t = uitable( app.Tab_ContMatch,  'Data', magic(5))
            %             f = figure('Position', [100 100 752 250]);
%             app.Tableload = uitable(app.Tab_ContMatch);
%             app.UITable.Data = {1 , 2 , 3 , 4};
% % % %             app.UITable.Data(:,2:3)=0
% % % %             app.UITable.ColumnFormat(:,2)=({'char'});
% % % %             app.UITable.ColumnFormat(:,3)=({'char'});
% % % %             app.UITable.ColumnEditable=[false true true];
        end

        % Value changed function: Initials
        function Initials_Changed(app, event)
            subName = app.Initials.Value;
            subName = upper(subName);
            
            
        aa = cd('/Users/clemente/Desktop/AfterImage 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

        else
        app.Field_RG_Ratio.Value = 0;
        app.Field_BG_Ratio.Value = 0

                     
        end
        end

        % Button pushed function: RunHFP
        function Run_HFP_Push(app, event)
subName =  app.Initials.Value
subName = upper(subName);

if strcmp('',subName)% 
    warndlg('The field "Subject Initials" is empty','Initials required')
    return
end

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

        % Button pushed function: RunContMatch
        function Run_ContMatch_Push(app, event)
subName =  app.Initials.Value
subName = upper(subName);

if strcmp('',subName)% 
    warndlg('The field "Subject Initials" is empty','Initials required')
    return
end

AdaptTime = app.AdaptContMatch.Value;
meanLum = app.LumContMatch.Value; 
Bckg_Chro = evalin('base', 'Bckg_Chro');


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; 1] ;end
if lum_axis_check;  curr_cond = [curr_cond; 2] ;end

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

ContMatch_session(subName,meanLum,Bckg_Chro,AdaptTime,curr_cond)

Screen('CloseAll'); sca;

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


        end

        % Button pushed function: DisplayColor
        function DisplayColor_Pushed(app, event)
subName =  app.Initials.Value
subName = upper(subName);
curr_Col_Sel = app.Butt_Group_Disp_Select.SelectedObject.Text
            
if strcmp(curr_Col_Sel,'Subject chromaticities') && strcmp('',subName)% 
    warndlg('The field "Subject Initials" is empty','Initials required')
    return
end

l_value = app.CD_littleL_Field.Value;
s_value = app.CD_littleS_Field.Value;
hfpRG = app.Field_RG_Ratio.Value; 
hfpBG = app.Field_BG_Ratio.Value; 

Disp_Color(l_value,s_value,hfpRG,hfpBG)


        end

        % Selection changed function: Butt_Group_Disp_Select
        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'
        
        if strcmp('',subName)% 
            warndlg('The field "Subject Initials" is empty','Initials required')
            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';
        else

            aa = cd('/Users/clemente/Desktop/AfterImage 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';
            app.CD_littleL_Field.Value = .665;
            app.CD_littleS_Field.Value = 1;
            app.CD_littleL_Field.Editable = 'on'; 
            app.CD_littleS_Field.Editable = 'on'; 
            app.CD_littleL_Field.Enable = 'on'; 
            app.CD_littleS_Field.Enable = 'on'; 

        end
        
        
        
    case 'Custom'
        
        app.Field_RG_Ratio.Value = 1
        app.Field_BG_Ratio.Value = 1
        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';
        



        
end
     
        end

        % Button pushed function: Run
        function Run_Exp_Pushed(app, event)
subName =  app.Initials.Value;
subName = upper(subName);

if strcmp('',subName)% 
    warndlg('The field "Subject Initials" is empty','Initials required')
    return
end

app.Run.Enable = 'off'; 
app.Stop.Enable = 'on'; 
Pupil_chck = app.Pupil.Value;
OneEnd_chck = app.OneEnd.Value;
OneHemi_chck = app.OneHemi.Value ;
Simu_chck = app.Simulate.Value;
AdapTime = app.AdaptTime.Value;
nRep = app.RepetExp.Value;
meanLum = app.Lum_Field.Value; 
% white = [app.littleL_Field.Value  app.littleS_Field.Value];
% Bckg_Chro = [ExpCond{:,2} ExpCond{:,3}];
Bckg_Chro = evalin('base', 'Bckg_Chro');

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;


axis_chck = [l_check ; s_check ; ls45_check ; ls135_check ; lum_check...
    ; lum_l_45_check ; lum_l_135_check ; lum_s_45_check; lum_s_135_check];


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

if Pupil_chck
        AfIm_pupil_Exp(subName,meanLum,Bckg_Chro,axis_chck,AdapTime,nRep,OneHemi_chck);
else
    if OneEnd_chck
        AfIm_OneEnd_Exp(subName,meanLum,Bckg_Chro,axis_chck,AdapTime,nRep,OneHemi_chck,Simu_chck);
    else
         AfIm_Exp_Rivalry(subName,meanLum,Bckg_Chro,axis_chck,AdapTime,nRep,Simu_chck);
    end
end

Screen('CloseAll'); sca;

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

        % Callback function
        function Field_BG_ratio_Changed(app, event)
            value = app.Field_BG_Ratio.Value;
            
        end

        % Button pushed function: Stop
        function Stop_Pushed(app, event)
%             Stop_Press=1
            assignin('base','Stop_Press',1)
%             Screen('CloseAll')
%             sca;
%             app.Run.Enable = 'on';
%             app.Stop.Enable = 'off';
        end

        % Value changed function: RepetExp
        function NRepetitions_Changed(app, event)
            nRep = app.RepetExp.Value;
            
        end

        % Value changed function: NumericEditField6
        function C1_Changed(app, event)
            s_C1 = app.NumericEditField6.Value;
            
        end

        % Button pushed function: Custom_Exp
        function Custom_Exp_Pushed(app, event)

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.RepetExp.Enable = 'on'; app.RepetExp.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

        % Button pushed function: Default_Exp
        function Default_Exp_Pushed(app, event)
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.RepetExp.Value = 3;
app.Lum_Field.Value = 20; 
app.littleL_Field.Value = 0.665; 
app.littleS_Field.Value = 1;  
        end

        % Button pushed function: Load_Exp
        function Load_Exp_Pushed(app, event)
cd('/Users/clemente/Desktop/AfterImage Programs/Experimental Conditions (zaidi paradigm)')
[FileName,PathName] = uigetfile('*.txt','Select the MATLAB code file');

if  FileName == 0% 
return

else
app.FilenameExp.Value = FileName; 
app.FilenameExp.Editable = 'off'

ExpCond = readtable(FileName,'Delimiter',',')
Bckg_Chro = [ExpCond{:,2} ExpCond{:,3}]; 
assignin('base','Bckg_Chro',Bckg_Chro);

f = figure('Position', [100 650 250 150]);
t = uitable(f,'Position', [25 25 200 100], 'Data', Bckg_Chro)
t.ColumnName = {'l_axis','s_axis'};

app.Lum_Field.Value = ExpCond{1,1}; 
app.littleL_Field.Value = ExpCond{1,2}; 
app.littleS_Field.Value = ExpCond{1,3};
app.AdaptTime.Value = ExpCond{1,4};
app.RepetExp.Value = ExpCond{1,5};
app.CheckBox.Value = ExpCond{1,6};
app.CheckBox2.Value = ExpCond{1,7};
app.CheckBox3.Value = ExpCond{1,8};
app.CheckBox4.Value = ExpCond{1,9};
app.CheckBox5.Value = ExpCond{1,10};
app.CheckBox6.Value = ExpCond{1,11};
app.CheckBox7.Value = ExpCond{1,12};
app.CheckBox8.Value = ExpCond{1,13};
app.CheckBox9.Value = ExpCond{1,14};
% 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.RepetExp.Value = str2num(Values{13});

end
        end

        % Callback function
        function Update_RGB_Pushed(app, event)
            
        end

        % Callback function
        function Update_Chromat_Pushed(app, event)
            
        end

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

        % Button pushed function: StopContMatch
        function StopContMatch_Pushed(app, event)
             assignin('base','Stop_Press',1)
%             Screen('CloseAll')
%             sca;
%             app.RunContMatch.Enable = 'on';
%             app.StopContMatch.Enable = 'off';
        end

        % Value changed function: AdaptTime
        function AdaptTimeChanged(app, event)
            AdaptTime = app.AdaptTime.Value;
            
        end

        % Value changed function: Simulate
        function SimulateChanged(app, event)
            Simulate = app.Simulate.Value;
            
            app.Initials.Value = 'YY';
            
        end

        % Button pushed function: LoadContMatch
        function LoadContMatchButtonPushed(app, event)
cd('/Users/clemente/Desktop/AfterImage Programs/Experimental Conditions (zaidi paradigm)')
[FileName,PathName] = uigetfile('*.txt','Select the MATLAB code file');

% file = 'H:\user4\matlab\myfile.txt';
% [filepath,name,ext] = fileparts(file)

if  FileName == 0% 
return

else
    
app.FileNameContMatch.Value = FileName; 
app.FileNameContMatch.Editable = 'off'

ExpCond = readtable(FileName,'Delimiter',',');
Bckg_Chro = [ExpCond{:,2} ExpCond{:,3}]; 
assignin('base','Bckg_Chro',Bckg_Chro);


% app.littleL_Field.Value = ExpCond{1,2}; 
% app.littleS_Field.Value = ExpCond{1,3};
app.AdaptContMatch.Value = ExpCond{1,4};


f= figure('Position', [100 650 250 150]);  
t = uitable(f,'Position', [25 25 200 100], 'Data', Bckg_Chro)
t.ColumnName = {'l_axis','s_axis'};


end
        end

        % Value changed function: OneEnd
        function OneEndSelect(app, event)
%             value = app.OneEnd.Value;
            app.OneHemi.Enable = 'on';
%             app.Pupil.Value = false;
            
        end

        % Value changed function: Pupil
        function PupilChanged(app, event)
%             value = app.Pupil.Value;
             app.OneEnd.Value = true;
              app.OneHemi.Value = false;
              app.Simulate.Value = false;
        end
    end

    % App initialization and construction
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure
            app.UIFigure = uifigure;
            app.UIFigure.Position = [101 101 658 491];
            app.UIFigure.Name = 'UI Figure';

            % Create LabelEditField
            app.LabelEditField = uilabel(app.UIFigure);
            app.LabelEditField.HorizontalAlignment = 'right';
            app.LabelEditField.VerticalAlignment = 'top';
            app.LabelEditField.Position = [13.03125 454 79 15];
            app.LabelEditField.Text = 'Subject Initials';

            % Create Initials
            app.Initials = uieditfield(app.UIFigure, 'text');
            app.Initials.ValueChangedFcn = createCallbackFcn(app, @Initials_Changed, true);
            app.Initials.Position = [107.03125 450 100 22];

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Position = [13 16 618 416];

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

            % Create HFP_Pair_Sel
            app.HFP_Pair_Sel = uipanel(app.Tab_HFP);
            app.HFP_Pair_Sel.Title = 'HFP Conditions';
            app.HFP_Pair_Sel.FontWeight = 'bold';
            app.HFP_Pair_Sel.Position = [18 254 583 127];

            % Create CheckBG
            app.CheckBG = uicheckbox(app.HFP_Pair_Sel);
            app.CheckBG.Enable = 'off';
            app.CheckBG.Text = 'B/G';
            app.CheckBG.Position = [9 58 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 = [9 35 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 = [10 13 39.4375 16];
            app.CheckBR.Value = true;

            % Create Label8
            app.Label8 = uilabel(app.HFP_Pair_Sel);
            app.Label8.VerticalAlignment = 'top';
            app.Label8.FontWeight = 'bold';
            app.Label8.FontAngle = 'italic';
            app.Label8.Position = [9 84 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, true);
            app.RunHFP.Position = [429 43 141 41];
            app.RunHFP.Text = 'Run';

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

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

            % Create DisplayColor
            app.DisplayColor = uibutton(app.Tab_Col_Disp, 'push');
            app.DisplayColor.ButtonPushedFcn = createCallbackFcn(app, @DisplayColor_Pushed, true);
            app.DisplayColor.Position = [251.96875 67 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.Position = [17 278 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 = [11 61 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 = [11 39 61.25 16];

            % Create Label13
            app.Label13 = uilabel(app.Tab_Col_Disp);
            app.Label13.HorizontalAlignment = 'right';
            app.Label13.VerticalAlignment = 'top';
            app.Label13.Enable = 'off';
            app.Label13.Position = [368 223 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.Editable = 'off';
            app.Field_RG_Ratio.Enable = 'off';
            app.Field_RG_Ratio.Position = [432 219 44 22];

            % Create Label14
            app.Label14 = uilabel(app.Tab_Col_Disp);
            app.Label14.HorizontalAlignment = 'right';
            app.Label14.VerticalAlignment = 'top';
            app.Label14.Enable = 'off';
            app.Label14.Position = [368 184 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.Editable = 'off';
            app.Field_BG_Ratio.Enable = 'off';
            app.Field_BG_Ratio.Position = [432 180 44 22];

            % Create Label15
            app.Label15 = uilabel(app.Tab_Col_Disp);
            app.Label15.HorizontalAlignment = 'right';
            app.Label15.VerticalAlignment = 'top';
            app.Label15.Enable = 'off';
            app.Label15.Position = [167 223 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.Editable = 'off';
            app.CD_littleL_Field.Enable = 'off';
            app.CD_littleL_Field.Position = [216 219 44 22];

            % Create Label16
            app.Label16 = uilabel(app.Tab_Col_Disp);
            app.Label16.HorizontalAlignment = 'right';
            app.Label16.VerticalAlignment = 'top';
            app.Label16.Enable = 'off';
            app.Label16.Position = [165 184 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.Editable = 'off';
            app.CD_littleS_Field.Enable = 'off';
            app.CD_littleS_Field.Position = [217 180 44 22];

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

            % Create Label18
            app.Label18 = uilabel(app.Tab_Col_Disp);
            app.Label18.VerticalAlignment = 'top';
            app.Label18.FontWeight = 'bold';
            app.Label18.Position = [393 256 63 15];
            app.Label18.Text = 'RGB ratios';

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

            % Create PanelContMatch
            app.PanelContMatch = uipanel(app.Tab_ContMatch);
            app.PanelContMatch.Title = 'Conditions';
            app.PanelContMatch.FontWeight = 'bold';
            app.PanelContMatch.Position = [13 178 589 171];

            % Create Label3
            app.Label3 = uilabel(app.PanelContMatch);
            app.Label3.HorizontalAlignment = 'right';
            app.Label3.VerticalAlignment = 'top';
            app.Label3.Position = [66.03125 102 20 15];
            app.Label3.Text = 'C1';

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

            % Create Label4
            app.Label4 = uilabel(app.PanelContMatch);
            app.Label4.HorizontalAlignment = 'right';
            app.Label4.VerticalAlignment = 'top';
            app.Label4.Position = [303.03125 102 20 15];
            app.Label4.Text = 'C3';

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

            % Create Label5
            app.Label5 = uilabel(app.PanelContMatch);
            app.Label5.HorizontalAlignment = 'right';
            app.Label5.VerticalAlignment = 'top';
            app.Label5.Position = [183.03125 102 20 15];
            app.Label5.Text = 'C2';

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

            % Create Label6
            app.Label6 = uilabel(app.PanelContMatch);
            app.Label6.HorizontalAlignment = 'right';
            app.Label6.VerticalAlignment = 'top';
            app.Label6.Position = [431.03125 102 20 15];
            app.Label6.Text = 'C4';

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

            % Create Check_l_axis
            app.Check_l_axis = uicheckbox(app.PanelContMatch);
            app.Check_l_axis.Text = 'Match l_axis contrasts';
            app.Check_l_axis.Position = [80 47 139.46875 16];
            app.Check_l_axis.Value = true;

            % Create Check_lum_axis
            app.Check_lum_axis = uicheckbox(app.PanelContMatch);
            app.Check_lum_axis.Text = 'Match lum_axis contrasts';
            app.Check_lum_axis.Position = [80 24 156.375 16];
            app.Check_lum_axis.Value = true;

            % Create Label7
            app.Label7 = uilabel(app.PanelContMatch);
            app.Label7.VerticalAlignment = 'top';
            app.Label7.FontWeight = 'bold';
            app.Label7.FontAngle = 'italic';
            app.Label7.Position = [72 127 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, true);
            app.RunContMatch.Position = [450 39 129 41];
            app.RunContMatch.Text = 'Run';

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

            % Create LoadContMatch
            app.LoadContMatch = uibutton(app.Tab_ContMatch, 'push');
            app.LoadContMatch.ButtonPushedFcn = createCallbackFcn(app, @LoadContMatchButtonPushed, true);
            app.LoadContMatch.Position = [13 359 105 22];
            app.LoadContMatch.Text = 'Load ';

            % Create FileNameContMatch
            app.FileNameContMatch = uieditfield(app.Tab_ContMatch, 'text');
            app.FileNameContMatch.Position = [141.03125 359 360 22];

            % Create LabelEditField2
            app.LabelEditField2 = uilabel(app.Tab_ContMatch);
            app.LabelEditField2.HorizontalAlignment = 'right';
            app.LabelEditField2.VerticalAlignment = 'top';
            app.LabelEditField2.Position = [509.03125 363 49 15];
            app.LabelEditField2.Text = 'Filename';

            % Create Label20
            app.Label20 = uilabel(app.Tab_ContMatch);
            app.Label20.HorizontalAlignment = 'right';
            app.Label20.VerticalAlignment = 'top';
            app.Label20.FontWeight = 'bold';
            app.Label20.Position = [93 145 100 15];
            app.Label20.Text = 'Adaptation (secs)';

            % Create AdaptContMatch
            app.AdaptContMatch = uieditfield(app.Tab_ContMatch, 'numeric');
            app.AdaptContMatch.Position = [208 141 41 22];
            app.AdaptContMatch.Value = 60;

            % Create Label21
            app.Label21 = uilabel(app.Tab_ContMatch);
            app.Label21.HorizontalAlignment = 'right';
            app.Label21.VerticalAlignment = 'top';
            app.Label21.Position = [95 108 103 15];
            app.Label21.Text = 'Luminance (cd/m2)';

            % Create LumContMatch
            app.LumContMatch = uieditfield(app.Tab_ContMatch, 'numeric');
            app.LumContMatch.Editable = 'off';
            app.LumContMatch.Enable = 'off';
            app.LumContMatch.Position = [208 104 35 22];
            app.LumContMatch.Value = 20;

            % Create Tab_ZaidiParad
            app.Tab_ZaidiParad = uitab(app.TabGroup);
            app.Tab_ZaidiParad.Title = 'Time varying Paradigm';

            % Create Panel
            app.Panel = uipanel(app.Tab_ZaidiParad);
            app.Panel.Title = 'Experiment Conditions';
            app.Panel.FontWeight = 'bold';
            app.Panel.Position = [18 17 537 367];

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

            % Create RepetExp
            app.RepetExp = uieditfield(app.Panel, 'numeric');
            app.RepetExp.ValueChangedFcn = createCallbackFcn(app, @NRepetitions_Changed, true);
            app.RepetExp.Position = [257.03125 67 41 22];
            app.RepetExp.Value = 1;

            % Create CheckBox
            app.CheckBox = uicheckbox(app.Panel);
            app.CheckBox.Enable = 'off';
            app.CheckBox.Text = 'l_parallel_axis';
            app.CheckBox.Position = [174 193 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 = [173 170 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 = [173 143 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 = [318 193 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 = [318 170 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 = [318 143 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 = [445 170 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 = [445 143 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 = [445 193 78.0625 16];
            app.CheckBox9.Value = true;

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

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

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

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

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

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

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

            % Create Label11
            app.Label11 = uilabel(app.Panel);
            app.Label11.VerticalAlignment = 'top';
            app.Label11.FontWeight = 'bold';
            app.Label11.Position = [308 219 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, true);
            app.Load_Exp.Position = [8 314 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, true);
            app.Custom_Exp.Position = [8 277 108 22];
            app.Custom_Exp.Text = 'Custom ';

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

            % Create Lum_Field
            app.Lum_Field = uieditfield(app.Panel, 'numeric');
            app.Lum_Field.Editable = 'off';
            app.Lum_Field.Enable = 'off';
            app.Lum_Field.Position = [266.03125 244 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, true);
            app.Default_Exp.Position = [8 238 108 22];
            app.Default_Exp.Text = 'Default ';

            % Create Simulate
            app.Simulate = uicheckbox(app.Panel);
            app.Simulate.ValueChangedFcn = createCallbackFcn(app, @SimulateChanged, true);
            app.Simulate.Text = 'Simulate responses';
            app.Simulate.Position = [9 11 124.578125 16];

            % Create Label19
            app.Label19 = uilabel(app.Panel);
            app.Label19.HorizontalAlignment = 'right';
            app.Label19.VerticalAlignment = 'top';
            app.Label19.FontWeight = 'bold';
            app.Label19.Position = [142.03125 102 100 15];
            app.Label19.Text = 'Adaptation (secs)';

            % Create AdaptTime
            app.AdaptTime = uieditfield(app.Panel, 'numeric');
            app.AdaptTime.ValueChangedFcn = createCallbackFcn(app, @AdaptTimeChanged, true);
            app.AdaptTime.Position = [257.03125 98 41 22];
            app.AdaptTime.Value = 60;

            % Create FilenameExp
            app.FilenameExp = uieditfield(app.Panel, 'text');
            app.FilenameExp.Position = [142.03125 315 308 22];

            % Create Label22
            app.Label22 = uilabel(app.Panel);
            app.Label22.HorizontalAlignment = 'right';
            app.Label22.VerticalAlignment = 'top';
            app.Label22.Position = [462.03125 319 49 15];
            app.Label22.Text = 'Filename';

            % Create OneHemi
            app.OneHemi = uicheckbox(app.Panel);
            app.OneHemi.Enable = 'off';
            app.OneHemi.Text = 'One Hemifield';
            app.OneHemi.Position = [85 40 95.03125 16];

            % Create Pupil
            app.Pupil = uicheckbox(app.Panel);
            app.Pupil.ValueChangedFcn = createCallbackFcn(app, @PupilChanged, true);
            app.Pupil.Text = 'Pupil Measurement';
            app.Pupil.Position = [9 204 122.8125 16];

            % Create OneEnd
            app.OneEnd = uicheckbox(app.Tab_ZaidiParad);
            app.OneEnd.ValueChangedFcn = createCallbackFcn(app, @OneEndSelect, true);
            app.OneEnd.Text = 'One end';
            app.OneEnd.Position = [27 57 64.8125 16];
        end
    end

    methods (Access = public)

        % Construct app
        function app = TVP_GENERATOR

            % 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