function GUI_slider

clc
clear
s=tf('s');
t = 0:0.01:10;
r = linspace(0,max(t),length(t)); 
l = 0*ones(size(t)).*(t>5);
e = 0*randn(size(t));
Gp = 100/(s*(s+10));
a = 0;
M = 1;
frv = logspace(-2,2,200);
fr1 = squeeze(freqresp(Gp,frv))

%// Create GUI controls
h1 = figure('Position',[0   580   680   520],'Units','Pixels');
subplot(2,1,1)
subplot(2,1,2)
h2 = figure('Position',[690   660   590   450],'Units','Pixels');
h3 = figure('Position',[5   400   850   100],'Units','Pixels');

figure(h3)

handles.Slider1 = uicontrol('Style','slider','Position',[100 50 300 40],'Min',0,'Max',20,'SliderStep',[.1 .1],'Callback',@SliderCallback);
addlistener(handles.Slider1,'Value','PreSet',@SliderCallback);
handles.Text1 = uicontrol('Style','Text','Position',[200 15 20 40],'String','a ','Fontsize',20);
handles.Edit1 = uicontrol('Style','Edit','Position',[230 30 60 25],'String','','Fontsize',14);

handles.Slider2 = uicontrol('Style','slider','Position',[500 50 300 40],'Min',1,'Max',50,'Value',1,'Callback',@SliderCallback);
addlistener(handles.Slider2,'Value','PreSet',@SliderCallback);
handles.Text2 = uicontrol('Style','Text','Position',[600 15 20 40],'String','M ','Fontsize',20);
handles.Edit2 = uicontrol('Style','Edit','Position',[630 30 60 25],'String','','Fontsize',14);

%
guidata(h3,handles); %// Update the handles structure.

    function SliderCallback(~,~) %// This is the slider callback, executed when you release it or press the arrows at each extremity. 
        figure(h3)
        handles = guidata(gcf);

        a = get(handles.Slider1,'Value');
        set(handles.Edit1,'String',num2str(a));
        M = get(handles.Slider2,'Value');
        set(handles.Edit2,'String',num2str(M));
        
        figure(h1)
        Gk = (s+a)/(s+a/M);
        fr2 = squeeze(freqresp(Gk,frv));
        
        y = lsim(feedback(Gk*Gp,1),r-e,t) + lsim(feedback(Gp,Gk),l,t);
        y=y';
      
        u = lsim(feedback(Gk,Gp),r-e,t) - lsim(feedback(Gk*Gp,1),l,t);
        u=u';
        
        subplot(211)
        plot(t,r-y,'r');
        
        ylabel('tracking error r-y','Fontsize',20)
        axis([min(t),max(t),-0.02,0.2]);
        subplot(212)
        plot(t,u,'r')
        ylabel('input u','Fontsize',20)
        axis([min(t),max(t),-0.2,0.2]);
        
        figure(h2)
        subplot(211)
        loglog(frv,abs(fr1),'b')
        hold on
        loglog(frv,abs(fr1.*fr2),'r')
        plot([min(frv) max(frv)],[1 1],'k')
        axis([min(frv) max(frv) 1e-5 1e5])
        hold off
        subplot(212)
        semilogx(frv,180/pi*phase(fr1),'b')
        hold on
        semilogx(frv,180/pi*phase(fr1.*fr2),'r')
        axis([min(frv) max(frv) -200 -60])
        plot([min(frv) max(frv)],[-180 -180],'k')
        hold off
        
    end

end