function typeafsCA4(hObject, eventdata, Empty_Button, Buttons, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, titles, uonoff, uonoffC, typeAFS, plotopt, lvText, lvSlider, type, lcs)

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

fa = 0.05;
comp = sum(data.afscomputed);

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 0];
    data.choosen = [0 0 0 0];
    
    data.full.isC = 0;
    data.full.isA = 0;
    
    data.full.AFSC = [];
    data.full.AFSA = [];
    
    set(uonoff(1), 'Value', 1);
    set(uonoffC(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 = 4;
    z = getsetvar(Polysettings(4), 4, data.maxz, 1, 0);
    
    set(hObject, 'Enable','off');
    set(gcf,'Pointer','Watch');
    pause(0.5);
    
    [T,tim,suc,Dn,Un,Sn,Vn] = initialnmfCA4(U, S, V, z, k, n, s, data.calca);
    
    if s < z
        U = Un(:,1:4);
        V = Vn(:,1:4);
        S = Sn(1:4,1:4);
        D = Dn;
    else
        U = U(:,1:4);
        S = S(1:4,1:4);
        V = V(:,1:4);
    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:4
        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 < -5.E-2
        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, 5.E-2, 0, 1);
        
        tall = data.D*data.V(:,1:4);
        tall = diag(1./tall(:,1))*tall;
        data.tall = tall(:,2:4);
        
        tcll = (pinv(data.U*data.S(:,1:4))*data.D)';
        tcll = diag(1./tcll(:,1))*tcll;
        data.tcll = tcll(:,2:4);
        
        data.isnmf = 1;
    end
end

set(Empty_Button,'UserData',data);

if data.isnmf == 0
    return;
end

if (type == 0) && (select == 1)
    if data.afscomputed(1) == 0
        
        M = nchoosek(1:size(data.D,1),3);
        ni = 0;
        for i=1:size(M,1)
            in = M(i,:);
            al = -data.U(in,2:4)\data.U(in,1);
            if min(min(data.U*[1; al])) > -1.E-15
                data.FIRPOLC.t(ni+1,:) = al';
                ni = ni+1;
            end
        end;
        data.FIRPOLC.surf = convhulln(data.FIRPOLC.t(:,1:3));
        
        if data.afscomputed(3) == 0
            data.afsC.xm = 1.05*[min(data.FIRPOLC.t(:,1)) max(data.FIRPOLC.t(:,1))];
            data.afsC.ym = 1.05*[min(data.FIRPOLC.t(:,2)) max(data.FIRPOLC.t(:,2))];
            data.afsC.zm = 1.05*[min(data.FIRPOLC.t(:,3)) max(data.FIRPOLC.t(:,3))];
        end
        
        M = nchoosek(1:size(data.D,2),3);
        ni = 0;
        for i=1:size(M,1)
            in = M(i,:);
            al = -data.V(in,2:4)\data.V(in,1);
            if min(min([1 al']*data.V')) > -1.E-15
                data.FIRPOLA.t(ni+1,:) = al';
                ni = ni+1;
            end
        end;
        data.FIRPOLA.surf = convhulln(data.FIRPOLA.t(:,1:3));
        
        if data.afscomputed(3) == 0
            data.afsA.xm = 1.05*[min(data.FIRPOLA.t(:,1)) max(data.FIRPOLA.t(:,1))];
            data.afsA.ym = 1.05*[min(data.FIRPOLA.t(:,2)) max(data.FIRPOLA.t(:,2))];
            data.afsA.zm = 1.05*[min(data.FIRPOLA.t(:,3)) max(data.FIRPOLA.t(:,3))];
        end
        
        data.afscomputed(1) = 1;
    end
    
%     axes(AxesC);
%     trisurf(data.FIRPOLC.surf,data.FIRPOLC.t(:,1),data.FIRPOLC.t(:,2),data.FIRPOLC.t(:,3), 'Facecolor','k', 'Facealpha', fa);
%     
%     axes(AxesA);
%     trisurf(data.FIRPOLA.surf,data.FIRPOLA.t(:,1),data.FIRPOLA.t(:,2),data.FIRPOLA.t(:,3), 'Facecolor','k', 'Facealpha', fa);
    
    set(uonoff(1), 'Value', 1);
    set(uonoffC(1), 'Value', 1);
    
end
if (type == 1) && (select == 1) && (data.afscomputed(2) == 0)
    set(uonoff(1), 'Value', 1);
    set(uonoffC(1), 'Value', 1);
    
    set(typeAFS(1), 'Enable', 'off');
    set(typeAFS(3), 'Enable', 'off');
    
    data = computefullafsCA4(hObject, data, Footnote, Polysettings);
    
    set(typeAFS(1), 'Enable', 'on');
    set(typeAFS(3), 'Enable', 'on');
    
    data.afscomputed(2) = 1;
end
if (type == 2) && (select == 1)
    if data.afscomputed(3) == 0
        
        tt = data.U*data.S;
        for i=1:size(data.D,1)
            data.INNPOLA.t(i,1:3) = tt(i,2:4)/tt(i,1);
        end
        data.INNPOLA.surf = convhulln(data.INNPOLA.t(:,1:3));
        
        tt = data.V*data.S;
        for i=1:size(data.D,2)
            data.INNPOLC.t(i,1:3) = tt(i,2:4)/tt(i,1);
        end
        data.INNPOLC.surf = convhulln(data.INNPOLC.t(:,1:3));
        
        data.afscomputed(3) = 1;
    end
    
    set(uonoff(1), 'Value', 1);
    set(uonoffC(1), 'Value', 1);
    
end
onoffButton(Buttons,[2 4:7],[]);

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

data.selectplot(type+1) = select;

data.isFP = data.selectplot(1);
data.isAFS = data.selectplot(2);
data.isIP = data.selectplot(3);

set(Empty_Button,'UserData',data);

if comp
    AFScam(1,:) = get(AxesA,'cameraPosition');
    AFStar(1,:) = get(AxesA, 'cameraTarget');
    AFSupv(1,:) = get(AxesA, 'cameraUpVector');
    
    AFScam(2,:) = get(AxesC,'cameraPosition');
    AFStar(2,:) = get(AxesC, 'cameraTarget');
    AFSupv(2,:) = get(AxesC, 'cameraUpVector');
end

% if type == 1
    plotafsCA4(AxesA, AxesC, AxesSOLA, AxesSOLC, data.afsA, data.afsC, data.FIRPOLA, data.FIRPOLC, data.INNPOLA, data.INNPOLC, data.isFP, data.isIP, data.isAFS, lcs, [0 0 0], [-1 -1], plotopt);
    
    plotaddsCA4(AxesA, AxesC, AxesSOLA, AxesSOLC, data.afsA, data.afsC, data.fixA, data.fixC, data.U*data.S, data.V', data.choosen, data.x, data.t,...
    data.givena, data.givenc, data.S(2:4,2:4),data.S(1,1), [], [], [], [], lcs, [], [], plotopt, 0, 0, [])
% else
%     liveviewCA4(hObject, eventdata, Empty_Button, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, -1, lcs, [0 0 0])
% end

if max(data.afscomputed)
    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 A');
        else
            set(titles(3), 'String', 'superset AFS factor C');
            set(titles(4), 'String', 'superset AFS factor A');
        end
    else
        if data.selectplot(2) == 1
            set(titles(3), 'String', 'full AFS factor C');
            set(titles(4), 'String', 'full AFS factor A');
        else
            set(titles(3), 'String', 'AFS factor C');
            set(titles(4), 'String', 'AFS factor A');
        end
    end
else
    plot(AxesSOLC,1,0,'w');
    plot(AxesSOLA,1,0,'w');
end

if comp
    set(AxesA, 'cameraPosition', AFScam(1,:));
    set(AxesA, 'cameraTarget', AFStar(1,:));
    set(AxesA, 'cameraUpVector', AFSupv(1,:));
    
    set(AxesC, 'cameraPosition', AFScam(2,:));
    set(AxesC, 'cameraTarget', AFStar(2,:));
    set(AxesC, 'cameraUpVector', AFSupv(2,:));
end