function liveview(hObject, eventdata, Empty_Button, Button,  AxesD,  AxesAFS,  AxesSOL, Radiogroup, usmn,usmf, basichi)


    
lcs = [0 0 1;0 0.5 0;1 0 0;0 0.5 0.5;0.5 0 0.5;0.5 0.5 0];
data = get(Empty_Button,'UserData');


if get(usmn, 'Value') == 0
    set(usmn, 'Value', 0);
    set(usmf, 'Value', 1);
    return;
end

if isfield(data,'isafs')==0 || data.isafs==0
    set(usmn, 'Value', 0);
    set(usmf, 'Value', 1);
    return;
end
    
SelTyp = get(gcbf, 'SelectionType');


data = get(Empty_Button,'UserData');


plot(AxesSOL,data.x,0,'w');
    yl = get(AxesAFS,'ylim');
    xl = get(AxesAFS,'xlim');
    pt = get(AxesAFS,'CurrentPoint');


x = pt(1,1:2);

pt = get(hObject, 'CurrentPoint');
sz = get(hObject, 'Position');
xf = pt(1,1:2)./sz(1,3:4);

posAFS = get(AxesAFS, 'Position');


% if strcmp(SelTyp,'alt') == 1
if (posAFS(1) < xf(1)) && (xf(1) < posAFS(1)+posAFS(3)) && (posAFS(2) < xf(2)) && (xf(2) < posAFS(2)+posAFS(4))
    
    if data.Sraw(3,3) <10^(-10)
        if data.scalBorg==1
            if (data.mima_B(1,1) < x(1)) && (data.mima_B(1,2) > x(1)) && (data.mima_B(2,1) < x(2)) && (data.mima_B(2,2) > x(2))
                lw = 2;
            else
                lw = 0.5;
            end
        else
            if (data.mima_SV(1,1) < x(1)) && (data.mima_SV(1,2) > x(1)) && (data.mima_SV(2,1) < x(2)) && (data.mima_SV(2,2) > x(2))
                lw = 2;
            else
                lw = 0.5;
            end
        end

        
        xlabel(AxesSOL,'channel / time');
        
        xli = [min(data.x), max(data.x)];
        yli = 1.1*[min([0, data.mima(1,3), data.mima(2,3)]), max(data.mima(1,4), data.mima(2,4))];
        
        posX = xli(1)+0.65*(xli(2)-xli(1));
        posY = yli(1)+0.9*(yli(2)-yli(1));
        text(posX,posY,['(x,y) = (',num2str(x(1),'%4.4f'),', ',num2str(x(2),'%4.4f'),')'],...
            'fontsize',2*basichi,'FontWeight','bold','Parent',AxesSOL);
        
        set(AxesSOL,'ylim',yli,'xlim',xli,'YTick',[0]);
    else
        
        ExpMode = 1;
        hold(AxesSOL,'off');
        if (isfield(data,'isExpert1') == 1) && (data.isExpert1 == 1)
            ExpMode = 2;
            
            if (isfield(data,'isExpert2') == 1) && (data.isExpert2 == 1)
                ExpMode = 3;
            end
        end
        
        if data.isafs == 1
            data.isLastClickLockMode = 1;
            data.LastClickLockMode.FixPoint = x;
            data.LastClickLockMode.a = [1 x]*data.Vraw(:,1:3)';
            
            if data.scalBorg==1
                mima=data.mima_B;
                segments=data.segments_B;
                FP=data.FP_B;
                Tbnd=data.Tbnd_B;
            else
                mima=data.mima_SV;
                segments=data.segments_SV;
                FP=data.FP_SV;
                Tbnd=data.Tbnd_SV;
            end
                
            
            if data.numb_seg >= 3
                inn = 0;
                for i=1:data.numb_seg
                    %                      if data.valid(i) == 1
                    if (mima(i,1) < x(1)) && (mima(i,2) > x(1)) && (mima(i,3) < x(2)) && (mima(i,4) > x(2))
                        if inpolygon(x(1), x(2), segments{i}(:,1), segments{i}(:,2))
                            if i<=6
                                if data.scalBorg==0
                                    plot(AxesSOL,data.x,[1 x]*data.Vraw(:,1:3)','color',lcs(i,:),'Linewidth',2);
                                else
                                    plot(AxesSOL,data.x,[(1-data.sum_v2*x(1)-data.sum_v3*x(2))/data.sum_v1 x]*data.V_scal(:,1:3)','color',lcs(i,:),'Linewidth',2);
                                end
                                data.colorExpert(ExpMode,:) = lcs(i,:);
                            else
                                if data.scalBorg==0
                                    plot(AxesSOL,data.x,[1 x]*data.Vraw(:,1:3)','color',[0 0 0],'Linewidth',2);
                                else
                                    plot(AxesSOL,data.x,[(1-data.sum_v2*x(1)-data.sum_v3*x(2))/data.sum_v1 x]*data.V_scal(:,1:3)','color',[0 0 0],'Linewidth',2);
                                end
                                data.colorExpert(ExpMode,:) = [0 0 0];
                            end
                            
                            xli = [min(data.x), max(data.x)];
                            
                            yli = 1.1*[min(0, mima(i,5)), mima(i,6)];
                            
                            posX = xli(1)+0.65*(xli(2)-xli(1));
                            posY = yli(1)+0.9*(yli(2)-yli(1));
                            text(posX,posY,['(x,y) = (',num2str(x(1),'%4.4f'),', ',num2str(x(2),'%4.4f'),')'],...
                                'fontsize',2*basichi,'FontWeight','bold','Parent',AxesSOL);
                            
                            set(AxesSOL,'ylim',yli,'xlim',xli);
                            xlabel(AxesSOL,'channel');
                            inn = 1;
                        end
                    end
                    if inn == 1
                        break;
                    end
                    %                     end
                    
                    if inn == 0
                        if data.scalBorg==0
                            plot(AxesSOL,data.x,[1 x]*data.Vraw(:,1:3)','--k','Linewidth',1);

                        else
                            plot(AxesSOL,data.x,[(1-data.sum_v2*x(1)-data.sum_v3*x(2))/data.sum_v1 x]*data.V_scal(:,1:3)','--k','Linewidth',1);

                        end
                        xli = [min(data.x), max(data.x)];
                        yli = 1.1*[min(0, min(mima(:,5))), max(mima(:,6))];
                        
                        posX = xli(1)+0.65*(xli(2)-xli(1));
                        posY = yli(1)+0.9*(yli(2)-yli(1));
                        text(posX,posY,['(x,y) = (',num2str(x(1),'%4.4f'),', ',num2str(x(2),'%4.4f'),')'],...
                            'fontsize',2*basichi,'FontWeight','bold','Parent',AxesSOL);
                        
                        set(AxesSOL,'ylim',yli,'xlim',xli);
                        xlabel(AxesSOL,'channel');
                    end
                end
            elseif data.numb_seg == 1
                inn(1:2) = 0;
                for i=1:2
   
                        if inpolygon(x(1), x(2), FP(:,1), FP(:,2))
                            inn(1)=1;
                        end
                        if inpolygon(x(1), x(2), Tbnd(:,1), Tbnd(:,2))
                            inn(2)=1;
                        end
          
                        

                end
                if inn(1)>=1 && inn(2)<1

                    if data.scalBorg==0
                        plot(AxesSOL,data.x,[1 x]*data.Vraw(:,1:3)'/max([1 x]*data.Vraw(:,1:3)')*data.mima(1,6),'k','Linewidth',2);

                    else
                        plot(AxesSOL,data.x,[(1-data.sum_v2*x(1)-data.sum_v3*x(2))/data.sum_v1 x]*data.V_scal(:,1:3)','k','Linewidth',2);

                    end
                    data.colorExpert(ExpMode,:) = [0 0 0];
                    
                    xli = [min(data.x), max(data.x)];
                    yli = 1.1*[min(0, mima(1,5)), mima(1,6)];
                    
                    posX = xli(1)+0.65*(xli(2)-xli(1));
                    posY = yli(1)+0.9*(yli(2)-yli(1));
                    
                    text(posX,posY,['(x,y) = (',num2str(x(1),'%4.4f'),', ',num2str(x(2),'%4.4f'),')'],...
                        'fontsize',2*basichi,'FontWeight','bold','Parent',AxesSOL);
                    
                    set(AxesSOL,'ylim',yli,'xlim',xli);
                    xlabel(AxesSOL,'channel');
                else

                    if data.scalBorg==0
                        plot(AxesSOL,data.x,[1 x]*data.Vraw(:,1:3)','--k','Linewidth',1);
                    else
                        plot(AxesSOL,data.x,[(1-data.sum_v2*x(1)-data.sum_v3*x(2))/data.sum_v1 x]*data.V_scal(:,1:3)','--k','Linewidth',1);
                    end
                    xli = [min(data.x), max(data.x)];
                    yli = 1.1*[min(0, min(mima(:,5))), max(mima(:,6))];
                    
                    posX = xli(1)+0.65*(xli(2)-xli(1));
                    posY = yli(1)+0.9*(yli(2)-yli(1));
                    text(posX,posY,['(x,y) = (',num2str(x(1),'%4.4f'),', ',num2str(x(2),'%4.4f'),')'],...
                        'fontsize',2*basichi,'FontWeight','bold','Parent',AxesSOL);
                    
                    set(AxesSOL,'ylim',yli,'xlim',xli);
                    xlabel(AxesSOL,'channel');
                    
                end
            end
        end
        

        if (isfield(data,'isExpert1') == 1) && (data.isExpert1 == 1)
            hold(AxesSOL,'on');
            if data.scalBorg==0
                plot(AxesSOL,data.x,[1 data.FixPoint1_SV]*data.Vraw(:,1:3)','color',data.colorExpert(1,:),'Linewidth',2);
                
            else
                plot(AxesSOL,data.x,[(1-data.sum_v2*data.FixPoint1_B(1)-data.sum_v3*data.FixPoint1_B(2))/data.sum_v1 data.FixPoint1_B]*data.V_scal(:,1:3)','color',data.colorExpert(1,:),'Linewidth',2);
            end
            if (isfield(data,'isExpert2') == 1) && (data.isExpert2 == 1)
                hold(AxesSOL,'on');
                if data.scalBorg==0
                    plot(AxesSOL,data.x,[1 data.FixPoint2_SV]*data.Vraw(:,1:3)','color',data.colorExpert(2,:),'Linewidth',2);
                else
                    plot(AxesSOL,data.x,[(1-data.sum_v2*data.FixPoint2_B(1)-data.sum_v3*data.FixPoint2_B(2))/data.sum_v1 data.FixPoint2_B]*data.V_scal(:,1:3)','color',data.colorExpert(2,:),'Linewidth',2);
                end
            end
            
        end
        %%Abschnitt geht bis hier

    end
    hold(AxesSOL,'off');
    
    if strcmp(SelTyp,'alt')== 1
        
        if (isfield(data,'isExpert1') == 0) || (data.isExpert1 == 0)
            
            
            if data.scalBorg==1
                pt = get(AxesAFS, 'CurrentPoint');
                data.FixPoint1_B = pt(1,1:2);
                
                V1=data.V_scal;
                VTV = V1'*data.Vraw;
                s1=data.sum_v1;
                s2=data.sum_v2;
                s3=data.sum_v3;
                
                t(2:3)=data.FixPoint1_B;
                t(1)=(1-t(2)*s2-t(3)*s3)/s1;
                s=t*VTV;
                s=s/s(1);
                data.FixPoint1_SV(1:2)=s(2:3);
                
            else
                pt = get(AxesAFS, 'CurrentPoint');
                data.FixPoint1_SV = pt(1,1:2);
                
                [h,n]=size(data.Vraw);
                e=ones(h,1);
                t1=[1,data.FixPoint1_SV(1),data.FixPoint1_SV(2)];
                
                h=t1*data.Vraw(:,1:3)';
                s=h*e;
                
                t2=h*V1/s;
                data.FixPoint1_B(1:2)=t2(2:3);
            end
%             data.isExpert1=1;
            set(Empty_Button,'UserData',data);


            if data.Borgen==1
                dlmwrite('wrap/FixPoint1.txt',data.FixPoint1_B','precision','%15.15e');
            else
                dlmwrite('wrap/FixPoint1.txt',data.FixPoint1_SV','precision','%15.15e');
            end

            plotAFS(Empty_Button,AxesAFS)
            

            
            set(usmn, 'Value', 0);
            set(usmf, 'Value', 1);
            
            
            
        elseif (isfield(data,'isExpert2') == 0) || (data.isExpert2 == 0)
            
            
             if data.scalBorg==1
                pt = get(AxesAFS, 'CurrentPoint');
                data.FixPoint2_B = pt(1,1:2);
                
                V1=data.V_scal;
                VTV = V1'*data.Vraw;
                s1=data.sum_v1;
                s2=data.sum_v2;
                s3=data.sum_v3;
                
                t(2:3)=data.FixPoint2_B;
                t(1)=(1-t(2)*s2-t(3)*s3)/s1;
                s=t*VTV;
                s=s/s(1);
                data.FixPoint2_SV(1:2)=s(2:3);
                
             else
                pt = get(AxesAFS, 'CurrentPoint');

                data.FixPoint2_SV = pt(1,1:2);
                
                [h,n]=size(data.Vraw);
                e=ones(h,1);
                t1=[1,data.FixPoint2_SV(1),data.FixPoint2_SV(2)];
                
                h=t1*data.Vraw(:,1:3)';
                s=h*e;
                
                t2=h*V1/s;
                data.FixPoint2_B(1:2)=t2(2:3);
            end
            set(Empty_Button,'UserData',data);
            
            if data.Borgen==1
                dlmwrite('wrap/FixPoint2.txt',data.FixPoint2_B','precision','%15.15e');
            else
                dlmwrite('wrap/FixPoint2.txt',data.FixPoint2_SV','precision','%15.15e');
            end
            plotAFSLock(Empty_Button, AxesAFS, 1)
            
            if data.scalBorg==1
                hold(AxesAFS, 'on');
                plot(AxesAFS,data.FixPoint1_B(1),data.FixPoint1_B(2),'kx','Linewidth',2);
                plot(AxesAFS,data.FixPoint2_B(1),data.FixPoint2_B(2),'ko','Linewidth',2);
                hold(AxesAFS, 'off');
            else
                hold(AxesAFS, 'on');
                plot(AxesAFS,data.FixPoint1_SV(1),data.FixPoint1_SV(2),'kx','Linewidth',2);
                plot(AxesAFS,data.FixPoint2_SV(1),data.FixPoint2_SV(2),'ko','Linewidth',2);
                hold(AxesAFS, 'off');
            end

            set(usmn, 'Value', 0);
            set(usmf, 'Value', 1);
            
            
        else
            
            if data.scalBorg==1
                pt = get(AxesAFS, 'CurrentPoint');
                data.FixPoint3_B = pt(1,1:2);
                
                V1=data.V_scal;
                VTV = V1'*data.Vraw;
                s1=data.sum_v1;
                s2=data.sum_v2;
                s3=data.sum_v3;
                
                t(2:3)=data.FixPoint3_B;
                t(1)=(1-t(2)*s2-t(3)*s3)/s1;
                s=t*VTV;
                s=s/s(1);
                data.FixPoint3_SV(1:2)=s(2:3);
                
             else
                pt = get(AxesAFS, 'CurrentPoint');

                data.FixPoint3_SV = pt(1,1:2);
                
                [h,n]=size(data.Vraw);
                e=ones(h,1);
                t1=[1,data.FixPoint3_SV(1),data.FixPoint3_SV(2)];
                
                h=t1*data.Vraw(:,1:3)';
                s=h*e;
                
                t2=h*V1/s;
                data.FixPoint3_B(1:2)=t2(2:3);
            end
            
            plotAFSLock(Empty_Button, AxesAFS, 2)
            
            if data.scalBorg==1
                hold(AxesAFS, 'on');
                plot(AxesAFS,data.FixPoint1_B(1),data.FixPoint1_B(2),'kx','Linewidth',2);
                plot(AxesAFS,data.FixPoint2_B(1),data.FixPoint2_B(2),'ko','Linewidth',2);
                plot(AxesAFS,data.FixPoint3_B(1),data.FixPoint3_B(2),'k+','Linewidth',2);

                hold(AxesAFS, 'off');
            else
                hold(AxesAFS, 'on');
                plot(AxesAFS,data.FixPoint1_SV(1),data.FixPoint1_SV(2),'kx','Linewidth',2);
                plot(AxesAFS,data.FixPoint2_SV(1),data.FixPoint2_SV(2),'ko','Linewidth',2);
                plot(AxesAFS,data.FixPoint3_SV(1),data.FixPoint3_SV(2),'k+','Linewidth',2);
                A=data.FixPoint1_B;
                B=data.FixPoint2_B;
                C=data.FixPoint3_B;
                plot([A(1) B(1) C(1) A(1)],[A(2) B(2) C(2) A(2)],'k');
                hold(AxesAFS, 'off');
            end

            
            
            set(usmn, 'Value', 0);
            set(usmf, 'Value', 1);
            
        end
        
    end
    
    
end
set(Empty_Button,'UserData',data);

