function button_changenorm(hObject, eventdata, parentfig,Empty_Button,titles,LockMode,Footnote, AxesAFS1,AxesAFS2,AxesSOL)

data = get(Empty_Button,'UserData');

if (isfield(data,'isafs') == 0) || (data.isafs == 0)
    set(Footnote,'String',' Warning, no AFS has been computed.','ForegroundColor','red')
    return
end



V1=data.V_scal;


if data.Borgen==1
         set(titles(5),'String','Generalized Borgen plot - FSV scaling');

    singv = diag(data.Sraw);
    if singv(2)/singv(1)-1 > -1.E-15
        str = ['No change of scaling possible: matrix D^TD reducible.'];
        set(Footnote,'String',str,'ForegroundColor','red');
        
        plot(AxesAFS1,0,0,'w');
        plot(AxesAFS2,0,0,'w');
        plot(AxesSOL,1,0,'w');
        
        return;
    end
    
    data.Borgen=0;
    VTV = V1'*data.Vraw;
    s1=data.sum_v1;
    s2=data.sum_v2;
    s3=data.sum_v3;
    
    [m,n] = size(data.FP);
    for i=1:m
        t(2:3)=data.FP(i,1:2);
        t(1)=(1-t(2)*s2-t(3)*s3)/s1;
        s=t*VTV;
        s=s/s(1);
        data.FP(i,1:2)=s(2:3);
    end
    
    [m,n] = size(data.IP);
    for i=1:m
        t(2:3)=data.IP(i,1:2);
        t(1)=(1-t(2)*s2-t(3)*s3)/s1;
        s=t*VTV;
        s=s/s(1);
        data.IP(i,1:2)=s(2:3);
    end
    
    [m,n] = size(data.Fbnd);
    for i=1:m
        t(2:3)=data.Fbnd(i,1:2);
        t(1)=(1-t(2)*s2-t(3)*s3)/s1;
        s=t*VTV;
        s=s/s(1);
        data.Fbnd(i,1:2)=s(2:3);
    end
    
    [m,n] = size(data.Tbnd);
    for i=1:m
        t(2:3)=data.Tbnd(i,1:2);
        t(1)=(1-t(2)*s2-t(3)*s3)/s1;
        s=t*VTV;
        s=s/s(1);
        data.Tbnd(i,1:2)=s(2:3);
    end
    
    for j=1:data.numb_seg
        [m,n] = size(data.segments{j});
        for i=1:m
            t(2:3)=data.segments{j}(i,1:2);
            t(1)=(1-t(2)*s2-t(3)*s3)/s1;
            s=t*VTV;
            s=s/s(1);
            data.segments{j}(i,1:2)=s(2:3);
        end
    end
else
    set(titles(5),'String','Generalized Borgen plot - RS scaling');

    data.Polygon=0;
    [m,n]=size(data.FP);
    [h,n]=size(data.Vraw);
    e=ones(h,1);
    for i=1:m
        t1=[1,data.FP(i,1),data.FP(i,2)];
       
        h=t1*data.Vraw(:,1:3)';
        s=h*e;
 
        t2=h*V1/s;
        data.FP(i,1:2)=t2(2:3);
    end
    
    [m,n]=size(data.IP);
    for i=1:m
        t1=[1,data.IP(i,1),data.IP(i,2)];
        h=t1*data.Vraw(:,1:3)';
        s=h*e;
        t2=h*V1/s;
        data.IP(i,1:2)=t2(2:3);
    end
    
    [m,n]=size(data.Tbnd);
    for i=1:m
        t1=[1,data.Tbnd(i,1),data.Tbnd(i,2)];
        h=t1*data.Vraw(:,1:3)';
        s=h*e;
        t2=h*V1/s;
        data.Tbnd(i,1:2)=t2(2:3);
    end
    
    [m,n]=size(data.Fbnd);
    for i=1:m
        t1=[1,data.Fbnd(i,1),data.Fbnd(i,2)];
       h=t1*data.Vraw(:,1:3)';
        s=h*e;
        t2=h*V1/s;
        data.Fbnd(i,1:2)=t2(2:3);
    end
    
    
    for j=1:data.numb_seg
        [m,n]=size(data.segments{j});
        for i=1:m
            t1=[1,data.segments{j}(i,1),data.segments{j}(i,2)];
            h=t1*data.Vraw(:,1:3)';
            s=h*e;
            t2=h*V1/s;
            data.segments{j}(i,1:2)=t2(2:3);
        end
    end
    data.Borgen=1;
end

if data.numb_seg==3 || data.numb_seg==1
     
            for i=1:data.numb_seg
                    if data.Borgen==0
                        data.mima(i,:) = [min(data.segments{i}(:,1)), max(data.segments{i}(:,1)), min(data.segments{i}(:,2)), max(data.segments{i}(:,2)),...
                        min(min([ones(size(data.segments{i},1),1) data.segments{i}]*data.Vraw(:,1:3)')), max(max([ones(size(data.segments{i},1),1) data.segments{i}]*data.Vraw(:,1:3)'))];
                    else
                        a=zeros(size(data.segments{i},1),1);
                        for j=1:size(data.segments{i},1);
                            a(j)=(1-data.sum_v2*data.segments{i}(j,1)-data.sum_v3*data.segments{i}(j,2))/data.sum_v1;
                        end
                        
                        data.mima(i,:) = [min(data.segments{i}(:,1)), max(data.segments{i}(:,1)), min(data.segments{i}(:,2)), max(data.segments{i}(:,2)),...
                        min(min([a data.segments{i}]*data.V_scal(:,1:3)')), max(max([a data.segments{i}]*data.V_scal(:,1:3)'))];

                   end
            end
 end


set(hObject,'Enable','on');
data.isExpert1=0;
    data.isExpert2=0;

    data.AFSL=[];
    data.AFSL2=[];
    data.numb_segmentsL2=[];
    data.numb_segmentsL2=0;
    data.numb_segmentsL=[];
    data.numb_segmentsL=0;
    set(Empty_Button,'UserData',data);

set(Empty_Button,'UserData',data)

plotAFS(Empty_Button,AxesAFS1,AxesAFS2)
hold(AxesSOL,'off');
plot(AxesSOL,1,0,'w');


onoffButton(LockMode,2,3:5);



dlmwrite('wrap/IP.txt',data.IP,'precision','%15.15e','delimiter',' ');
dlmwrite('wrap/FP.txt',data.FP,'precision','%15.15e','delimiter',' ');
dlmwrite('wrap/AFS.txt',data.Tbnd,'precision','%15.15e','delimiter',' ');
dlmwrite('wrap/AFSout.txt',data.Fbnd,'precision','%15.15e','delimiter',' ');