function buttonsaveAFS(hObject, eventdata, Empty_Button, Buttons, Footnote, AxesAFS, AxesSOL, Plotsettings)
data = get(Empty_Button,'UserData');
if (isfield(data,'ismatrix')*isfield(data,'isnmf')*isfield(data,'isafs') == 0) || (data.ismatrix*data.isnmf*data.isafs == 0)
    if data.ismatrix == 0 set(Footnote,'String',' Warning, no data has been loaded.','ForegroundColor','red');return;end
    if data.isnmf == 0 set(Footnote,'String',' Warning, no NMF has been computed.','ForegroundColor','red');return;end
    if data.isafs == 0 set(Footnote,'String',' Warning, no AFS has been computed.','ForegroundColor','red');return;end
end
U = data.U; 
S = data.S;
V = data.V;
D = data.D;
x = data.x;
t = data.t;
Cinit = U*S(:,1:data.s)*pinv(data.InitT);
Ainit = data.InitT*V(:,1:data.s)';
Draw = data.Draw;

AFS = data.AFS;

if (isfield(data,'isLastClickLockMode') == 1) && (data.isLastClickLockMode == 1)
    if (isfield(data,'isExpert1') == 1) && (data.isExpert1 == 1)
        AFSLockMode1 = data.AFS1;
        LockPoint1 = data.FixPoint1;
        ALock1 = [1 data.FixPoint1]*V(:,1:data.s)';
        if (isfield(data,'isExpert2') == 1) && (data.isExpert2 == 1)
            AFSLockMode2 = data.AFS2;
            LockPoint2 = data.FixPoint2;
            ALock2 = [1 data.FixPoint2]*V(:,1:data.s)';
            
            LockPoint3 = data.LastClickLockMode.FixPoint;
            ALock3 = [1 LockPoint3]*V(:,1:data.s)';
            
            uisave({'U','S','V','D','x','t','Cinit','Ainit','AFS','AFSLockMode1','LockPoint1','ALock1',...
                'AFSLockMode2','LockPoint2','ALock2','LockPoint3','ALock3'},[data.PathName,'results_facpack_afs_',data.FileName]);
        else
            LockPoint2 = data.LastClickLockMode.FixPoint;
            ALock2 = [1 LockPoint2]*V(:,1:data.s)';
            
            uisave({'U','S','V','D','x','t','Cinit','Ainit','AFS','AFSLockMode1','LockPoint1','ALock1','LockPoint2','ALock2'},...
                [data.PathName,'results_facpack_afs_',data.FileName]);
        end
    else
        if data.s == 3
            LockPoint1 = data.LastClickLockMode.FixPoint;
            ALock1 = [1 LockPoint1]*V(:,1:data.s)';
            
            uisave({'U','S','V','D','Draw','x','t','Cinit','Ainit','AFS','LockPoint1','ALock1'},...
                [data.PathName,'results_facpack_afs_',data.FileName]);
        else
            LockPoint1 = data.LastClickLockMode.FixPoint(1);
            LockPoint2 = data.LastClickLockMode.FixPoint(2);
            
            ALock1 = [1 LockPoint1]*V(:,1:data.s)';
            ALock2 = [1 LockPoint2]*V(:,1:data.s)';
            
            A = [ALock1; ALock2];
            C = U*S(:,1:data.s)*pinv([1 LockPoint1; 1 LockPoint2]);
            
            uisave({'U','S','V','D','Draw','x','t','Cinit','Ainit','AFS','LockPoint1','ALock1',...
                'LockPoint2','ALock2','A','C'},[data.PathName,'results_facpack_all_',data.FileName]);
        end
    end
else
    if (isfield(data,'isExpert1') == 1) && (data.isExpert1 == 1)
        AFSLockMode1 = data.AFS1;
        LockPoint1 = data.FixPoint1;
        ALock1 = [1 data.FixPoint1]*V(:,1:data.s)';
        if (isfield(data,'isExpert2') == 1) && (data.isExpert2 == 1)
            AFSLockMode2 = data.AFS2;
            LockPoint2 = data.FixPoint2;
            ALock2 = [1 data.FixPoint2]*V(:,1:data.s)';
            uisave({'U','S','V','D','x','t','Cinit','Ainit','AFS','AFSLockMode1','LockPoint1','ALock1','AFSLockMode2','LockPoint2','ALock2'},...
                [data.PathName,'results_facpack_afs_',data.FileName]);
        else
            uisave({'U','S','V','D','x','t','Cinit','Ainit','AFS','AFSLockMode1','LockPoint1','ALock1'},[data.PathName,'results_facpack_afs_',data.FileName]);
        end
    else
        uisave({'U','S','V','D','Draw','x','t','Cinit','Ainit','AFS'},[data.PathName,'results_facpack_afs_',data.FileName]);
    end
end