function varargout = LaOla(varargin)
% LAOLA M-file for LaOla.fig
%      LAOLA, by itself, creates a new LAOLA or raises the existing
%      singleton*.
%
%      H = LAOLA returns the handle to a new LAOLA or the handle to
%      the existing singleton*.
%
%      LAOLA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LAOLA.M with the given input arguments.
%
%      LAOLA('Property','Value',...) creates a new LAOLA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before LaOla_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to LaOla_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help LaOla

% Last Modified by GUIDE v2.5 20-Sep-2004 14:30:48

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @LaOla_OpeningFcn, ...
    'gui_OutputFcn',  @LaOla_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before LaOla is made visible.
function LaOla_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to LaOla (see VARARGIN)

% Choose default command line output for LaOla
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes LaOla wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = LaOla_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes during object creation, after setting all properties.
function slider_Tm_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_Tm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_Tm_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_Tm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
tmax = get(handles.slider_Tm,'Value');
set(handles.Tm_value,'String',max(tmax,5));
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_L_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_L (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_L_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_L (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
L = get(handles.slider_L,'Value');
set(handles.L_value,'String',round(max(L,5)));
pos=1:1:L;
x=zeros(size(pos));
nx=x;
t0=zeros(size(pos));
Rm = get(handles.slider_Rm,'Value');
LL=Rm+1;
xe=1:1:L+2*LL;
t = 0;
for i = round(L/2):round(L/2)+s0
    t0(i)=0;
    x(i)=1;
end
xe(1:LL)=x(L-LL+1:L);
xe(LL+1:LL+L)=x(1:L);
xe(L+LL+1:L+2*LL)=x(1:LL);
axes(handles.axes4)
delta = get(handles.slider_delta,'Value');
c = get(handles.slider_c,'Value');
s_th=rand(1,L)*2*delta+c-delta;
plot(s_th,'.r'),axis([0 L -2.5 7.5])
hold  on
plot(s_th,'b')
hold off
title('Threshold of enthusiasm')

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_dt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_dt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_dt_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_dt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
dt = get(handles.slider_dt,'Value');
set(handles.dt_value,'String',max(dt,0.1));
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_s0_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_s0 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_s0_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_s0 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
s0 = get(handles.slider_s0,'Value');
set(handles.s0_value,'String',round(max(s0,1)));
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_step_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_step (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_step_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_step (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
step = get(handles.slider_step,'Value');
set(handles.step_value,'String',step);
axes(handles.axes2)
act = get(handles.slider_act,'Value');
b = get(handles.slider_b,'Value');
tttt=-20:0.01:20;
plot(tttt,sign(max(1./cosh(b*(tttt-step)),act)-act)...
    ./cosh(b*(tttt-step)),'LineWidth',2)
xlabel('time')
ylabel('level of enthusiasm')
title('Wave form')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_b_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_b (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_b_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_b (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
b = get(handles.slider_b,'Value');
set(handles.b_value,'String',b);
axes(handles.axes2)
act = get(handles.slider_act,'Value');
step = get(handles.slider_step,'Value');
tttt=-20:0.01:20;
plot(tttt,sign(max(1./cosh(b*(tttt-step)),act)-act)...
    ./cosh(b*(tttt-step)),'LineWidth',2)
xlabel('time')
ylabel('level of enthusiasm')
title('Wave form')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_a_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_a (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_a_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_a (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
a = get(handles.slider_a,'Value');
set(handles.a_value,'String',a);
axes(handles.axes3)
Rm = round(max(get(handles.slider_Rm,'Value'),1));
R = max(get(handles.slider_R,'Value'),0.0001);
tttt=-10:0.01:10;
plot(tttt,exp(-abs(tttt)/R).*(1-tanh(a*tttt)),'LineWidth',2)
hold on
y=-Rm:1:Rm;
weight=exp(-abs(y)/R).*(1-tanh(a*y));
plot(y,weight,'ro')
hold off
xlabel('position')
title('Effect of neighbors')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_act_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_act (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_act_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_act (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
act = get(handles.slider_act,'Value');
set(handles.act_value,'String',act);
axes(handles.axes2)
b = get(handles.slider_b,'Value');
step = get(handles.slider_step,'Value');
tttt=-20:0.01:20;
plot(tttt,sign(max(1./cosh(b*(tttt-step)),act)-act)...
    ./cosh(b*(tttt-step)),'LineWidth',2)
xlabel('time')
ylabel('level of enthusiasm')
title('Wave form')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_Rm_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_Rm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_Rm_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_Rm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Rm = get(handles.slider_Rm,'Value');
set(handles.Rm_value,'String',round(max(Rm,1)));
LL=Rm+1;
L = get(handles.slider_L,'Value');
xe=1:1:L+2*LL;
xe(1:LL)=x(L-LL+1:L);
xe(LL+1:LL+L)=x(1:L);
xe(L+LL+1:L+2*LL)=x(1:LL);
axes(handles.axes3)
a = get(handles.slider_a,'Value');
R = max(get(handles.slider_R,'Value'),0.0001);
tttt=-10:0.01:10;
plot(tttt,exp(-abs(tttt)/R).*(1-tanh(a*tttt)),'LineWidth',2)
hold on
y=-Rm:1:Rm;
weight=exp(-abs(y)/R).*(1-tanh(a*y));
plot(y,weight,'ro')
hold off
xlabel('position')
title('Effect of neighbors')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_c_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_c (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_c_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_c (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
c = get(handles.slider_c,'Value');
set(handles.c_value,'String',c);
axes(handles.axes4)
delta = get(handles.slider_delta,'Value');
L = round(max(get(handles.slider_L,'Value'),5));
s_th=rand(1,L)*2*delta+c-delta;
plot(s_th,'.r'),axis([0 L -2.5 7.5])
hold  on
plot(s_th,'b')
hold off
title('Threshold of enthusiasm')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_delta_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_delta (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_delta_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_delta (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
delta = get(handles.slider_delta,'Value');
set(handles.delta_value,'String',delta);
axes(handles.axes4)
c = get(handles.slider_c,'Value');
L = round(max(get(handles.slider_L,'Value'),5));
s_th=rand(1,L)*2*delta+c-delta;
plot(s_th,'.r'),axis([0 L -2.5 7.5])
hold  on
plot(s_th,'b')
hold off
title('Threshold of enthusiasm')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider_R_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider_R (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_R_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to slider_R (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
R = get(handles.slider_R,'Value');
set(handles.R_value,'String',max(R,0.0001));
init = 0;
axes(handles.axes3)
Rm = round(max(get(handles.slider_Rm,'Value'),1));
a = get(handles.slider_a,'Value');
tttt=-10:0.01:10;
plot(tttt,exp(-abs(tttt)/R).*(1-tanh(a*tttt)),'LineWidth',2)
hold on
y=-Rm:1:Rm;
weight=exp(-abs(y)/R).*(1-tanh(a*y));
plot(y,weight,'ro')
hold off
xlabel('position')
title('Effect of neighbors')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
L = round(max(get(handles.slider_L,'Value'),5));
s0 = round(max(get(handles.slider_s0,'Value'),1))-1;
Rm = round(max(get(handles.slider_Rm,'Value'),1));
tmax = max(get(handles.slider_Tm,'Value'),5);
dt = max(get(handles.slider_dt,'Value'),0.1);
step = get(handles.slider_step,'Value');
b = get(handles.slider_b,'Value');
a = get(handles.slider_a,'Value');
act = get(handles.slider_act,'Value');
c = get(handles.slider_c,'Value');
delta = get(handles.slider_delta,'Value');
R = max(get(handles.slider_R,'Value'),0.0001);
%
axes(handles.axes2)
tttt=-20:0.01:20;
plot(tttt,sign(max(1./cosh(b*(tttt-step)),act)-act)...
    ./cosh(b*(tttt-step)),'LineWidth',2)
xlabel('time')
ylabel('level of enthusiasm')
title('Wave form')
%
LL=Rm+1;
pos=1:1:L;
x=zeros(size(pos));
nx=x;
t0=zeros(size(pos));
xe=1:1:L+2*LL;
s_th=rand(1,L)*2*delta+c-delta;
axes(handles.axes4)
plot(s_th,'.r'),axis([0 L -2.5 7.5])
hold  on
plot(s_th,'b')
hold off
title('Threshold of enthusiasm')
%
y=-Rm:1:Rm;
weight=exp(-abs(y)/R).*(1-tanh(a*y));
axes(handles.axes3)
tttt=-10:0.01:10;
plot(tttt,exp(-abs(tttt)/R).*(1-tanh(a*tttt)),'LineWidth',2)
hold on
plot(y,weight,'ro')
hold off
xlabel('position')
title('Effect of neighbors')
%
t = 0;
set(handles.t_value,'String',t);
for i = round(L/2):round(L/2)+s0
    t0(i)=0;
    x(i)=1;
end
xe(1:LL)=x(L-LL+1:L);
xe(LL+1:LL+L)=x(1:L);
xe(L+LL+1:L+2*LL)=x(1:LL);
%
axes(handles.axes1)
bar(x), axis([0 L 0 1])
run = 0;
init = 1;


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global x pos nx xe t0 s_th weight y
global t LL run L s0 Rm tmax dt step b a act d delta R init
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if init == 0
    L = round(max(get(handles.slider_L,'Value'),5));
    s0 = round(max(get(handles.slider_s0,'Value'),1))-1;
    Rm = round(max(get(handles.slider_Rm,'Value'),1));
    tmax = max(get(handles.slider_Tm,'Value'),5);
    dt = max(get(handles.slider_dt,'Value'),0.1);
    step = get(handles.slider_step,'Value');
    b = get(handles.slider_b,'Value');
    a = get(handles.slider_a,'Value');
    act = get(handles.slider_act,'Value');
    c = get(handles.slider_c,'Value');
    delta = get(handles.slider_delta,'Value');
    R = max(get(handles.slider_R,'Value'),0.0001);
    %
    axes(handles.axes2)
    tttt=-20:0.01:20;
    plot(tttt,sign(max(1./cosh(b*(tttt-step)),act)-act)...
        ./cosh(b*(tttt-step)),'LineWidth',2)
    xlabel('time')
    ylabel('level of enthusiasm')
    title('Wave form')
    %
    LL=Rm+1;
    pos=1:1:L;
    x=zeros(size(pos));
    nx=x;
    t0=zeros(size(pos));
    xe=1:1:L+2*LL;
    s_th=rand(1,L)*2*delta+c-delta;
    axes(handles.axes4)
    plot(s_th,'.r'),axis([0 L -2.5 7.5])
    hold  on
    plot(s_th,'b')
    hold off
    title('Threshold of enthusiasm')
    %
    y=-Rm:1:Rm;
    weight=exp(-abs(y)/R).*(1-tanh(a*y));
    axes(handles.axes3)
    tttt=-10:0.01:10;
    plot(tttt,exp(-abs(tttt)/R).*(1-tanh(a*tttt)),'LineWidth',2)
    hold on
    plot(y,weight,'ro')
    hold off
    xlabel('position')
    title('Effect of neighbors')
    %
    t = 0;
    for i = round(L/2):round(L/2)+s0
        t0(i)=0;
        x(i)=1;
    end
    xe(1:LL)=x(L-LL+1:L);
    xe(LL+1:LL+L)=x(1:L);
    xe(L+LL+1:L+2*LL)=x(1:LL);
    %
    axes(handles.axes1)
    bar(x), axis([0 L 0 1])
    pause(0.5)
    %
    init = 1;
end
run = 1;
while (t <= tmax) & (run == 1)
        t = t + dt;
        set(handles.t_value,'String',t);
        for i = 1:L
            if x(i) > act
                nx(i) = sign(max(1/cosh(b*(t - t0(i))),act)-act)...
                    *1/cosh(b*(t - t0(i)));
            else
                win=sign(max(xe(i-Rm+LL:i+Rm+LL)-act,zeros(size(y))));
                s=sum(win.*weight);
                if s >= s_th(i)
                    t0(i) = t + step;
                    nx(i) = 1/cosh(b*(t - t0(i)));
                else
                    nx(i)=0;
                end
            end
        end
        x=nx;
        xe(1:LL)=x(L-LL+1:L);
        xe(LL+1:LL+L)=x(1:L);
        xe(L+LL+1:L+2*LL)=x(1:LL);
        axes(handles.axes1)
        bar(x), axis([0 L 0 1])
        pause(0.5)
end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
global run
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
run = 0;


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
global run
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pos_size = get(handles.figure1,'Position');
% Call modaldlg with the argument 'Position'.
user_response = QuitLaOla('Title','Confirm Close');
switch user_response
    case {'Cancel'}
        % take no action
    case 'OK'
        % Prepare to close GUI application window
        run = 0;
        delete(handles.figure1)
end


