function typeafsCAA(hObject, eventdata, Empty_Button, Buttons, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, titles, uonoff, uonoffC, regcont, regcontC, typeAFS, ipia, type, lcs)

data = get(Empty_Button,'UserData');
if data.isdata == 0
    set(hObject, 'Value', 0);
    return;
end

select = get(hObject, 'Value');

if data.isnmf == 0
    data.isAFSC = 0;
    data.isAFSA = 0;
    
    data.AFSC = [];
    data.AFSA = [];
    
    data.fixA = [];
    data.fixC = [];
    data.choosenC = [0 0 0];
    data.choosen = [0 0 0];
    
    data.full.isC = 0;
    data.full.isA = 0;
    
    data.full.AFSC = [];
    data.full.AFSA = [];
    
    data.regcon = 0;
    data.regconC = 0;
    
    data.isregcon = zeros(1,3);
    data.isregconC = zeros(1,3);
    
    set(uonoff(1), 'Value', 1);
    set(uonoffC(1), 'Value', 1);
    set(regcont(1), 'Value', 1);
    set(regcontC(1), 'Value', 1);
    
    plot(AxesC,1,0,'w');
    plot(AxesA,1,0,'w');
    plot(AxesSOLC,1,0,'w');
    plot(AxesSOLA,1,0,'w');
    
    U = data.Uraw;
    S = data.Sraw;
    V = data.Vraw;
    
    [k,n] = size(data.D);
    s = 3;
    z = getsetvar(Polysettings(4), 3, data.maxz, 1, 0);
    
    set(hObject, 'Enable','off');
    set(gcf,'Pointer','Watch');
    pause(0.5);
    
    [T,tim,suc,Dn,Un,Sn,Vn] = initialnmfCAA(U, S, V, z, k, n, s, data.calca);
    
    if s < z
        U = Un(:,1:3);
        V = Vn(:,1:3);
        S = Sn(1:3,1:3);
        D = Dn;
    else
        U = U(:,1:3);
        S = S(1:3,1:3);
        V = V(:,1:3);
    end
    
    data.U = U;
    data.S = S;
    data.V = V;
    
    data.k = k;
    data.n = n;
    data.s = s;
    
    data.InitT = T;
    
    A = T*V';
    C = U*S*pinv(T);
    
    for i=1:3
        A(i,:) = A(i,:)/max(abs(A(i,:)));
        C(:,i) = C(:,i)/max(abs(C(:,i)));
    end
    
    noise = 1.001*min(min(min(A)), min(min(C)));
    
    if suc < 1
        set(Footnote, 'String', 'NMF-computation canceled or failed.', 'ForegroundColor', 'r');
        set(hObject,'Enable','on','Value',0);
        set(Empty_Button,'UserData',data);
        return;
    end
    if noise < -data.maxnoise
        set(Footnote, 'String', sprintf('NMF-computation failed: negative entries are too large (%2.2e), increase value for "no sing. vctrs.".', noise), 'ForegroundColor', 'r');
        set(hObject,'Enable','on','Value',0);
        set(Empty_Button,'UserData',data);
        return;
    else
        strfn = [' Initial NMF computation-time: ',num2str(tim,'%2.2f'),' s'];
        noise = -min(noise, -1.E-12);
        data.noiseC = -getsetvar(Polysettings(1), noise, data.maxnoise, 0, 1);
        
        tall = data.D*data.V(:,1:3);
        tall = diag(1./tall(:,1))*tall;
        data.tall = tall(:,2:3);
        
        tcll = (pinv(data.U*data.S(:,1:3))*data.D)';
        tcll = diag(1./tcll(:,1))*tcll;
        data.tcll = tcll(:,2:3);
        
        data.isnmf = 1;
    end
end

set(Empty_Button,'UserData',data);

if data.isnmf == 0
    return;
end

if (type == 0) && (select == 1) && (data.afscomputed(1) == 0)
    set(uonoff(1), 'Value', 1);
    set(uonoffC(1), 'Value', 1);
    set(regcont(1), 'Value', 1);
    set(regcontC(1), 'Value', 1);
    
    set(typeAFS(2), 'Enable', 'off');
    set(typeAFS(3), 'Enable', 'off');
    
    data = computesupersetafsCAA(hObject, data, Footnote, Polysettings);
    
    set(typeAFS(2), 'Enable', 'on');
    set(typeAFS(3), 'Enable', 'on');
    
    data.afscomputed(1) = 1;
end
if (type == 1) && (select == 1) && (data.afscomputed(2) == 0)
    set(uonoff(1), 'Value', 1);
    set(uonoffC(1), 'Value', 1);
    set(regcont(1), 'Value', 1);
    set(regcontC(1), 'Value', 1);
    
    set(typeAFS(1), 'Enable', 'off');
    set(typeAFS(3), 'Enable', 'off');
    
    data = computefullafsCAA(hObject, data, Footnote, Polysettings, ipia);
    
    set(typeAFS(1), 'Enable', 'on');
    set(typeAFS(3), 'Enable', 'on');
    data.afscomputed(2) = 1;
end
onoffButton(Buttons,2,[]);

set(gcf,'Pointer','arrow');
set(hObject,'Enable','on');

data.selectplot(type+1) = select;

if max(data.afscomputed) == 1
    onoffButton(Buttons,3:6,[]);
end

set(Empty_Button,'UserData',data);

isregcon = [0 0];   REGCON = [];
if (data.regcon > 0) && (data.isregcon(data.regcon) == 1)
    isregcon(1) = data.regcon;
    REGCON{1} = data.REGCON{isregcon(1)};
end
if (data.regconC > 0) && (data.isregconC(data.regconC) == 1)
    isregcon(2) = data.regconC;
    REGCON{2} = data.REGCONC{isregcon(2)};
end

if ~isempty(data.xla)
    plotafsCAA(AxesA, AxesC, AxesSOLA, AxesSOLC, data.xla, data.xlc, data.yla, data.ylc, data.x, data.t, data.AFSA, data.AFSC,...
               data.U*data.S, data.V', data.fixA, data.fixC, data.choosen, data.choosenC, isregcon, REGCON, data.full, data.selectplot, data.givena, data.givenc, data.tall, data.tcll, data.istrace, lcs, [data.isclosure data.isshift data.ispeakposition data.isxreverse]);
           
    if data.selectplot(1) == 1
        if data.selectplot(2) == 1
            set(titles(3), 'String', 'superset and full AFS factor C');
            set(titles(4), 'String', 'superset and full AFS factor S');
        else
            set(titles(3), 'String', 'superset AFS factor C');
            set(titles(4), 'String', 'superset AFS factor S');
        end
    else
        if data.selectplot(2) == 1
            set(titles(3), 'String', 'full AFS factor C');
            set(titles(4), 'String', 'full AFS factor S');
        else
            set(titles(3), 'String', 'AFS factor C');
            set(titles(4), 'String', 'AFS factor S');
        end
    end
else
    plot(AxesC,1,0,'w');
    plot(AxesA,1,0,'w');
    plot(AxesSOLC,1,0,'w');
    plot(AxesSOLA,1,0,'w');
end
