%Hodgkin-Huxley:

%
%találomra indítva a rendszert
starting =[0.5 0.5 0.5 -50]; %nyugalmi potenciál, lesz AP
%starting =[0.5 0.5 0.5 -89]; %nyugalmi potenciál, hiperpolarizált marad, nincs AP
%starting =[0.5 0.5 0.5 150]; %nyugalmi potenciál, túl magas membránpot, visszaáll
ySS=starting;
[t,x]=ode45('hhode',[0 200],ySS);
figure
if max(x(:,4))>0 && max(x(:,4))<50
    plot(t, x(:,4),'r')
    drawnow;
    hold on;
    
elseif max(x(:,4))>50
    plot(t, x(:,4),'b')
    drawnow;
    hold on;
    
else
    plot(t, x(:,4),'k')
    drawnow;
    hold on;
end
title('Threshold Behavior');
    xlabel('Time (ms)');
    ylabel('Transmembrane Voltage (mV)');
    xlim([-1 20]);

figure;
plot(t, x(:,3),'r')
hold on
plot(t, x(:,2),'k')
plot(t, x(:,1),'b')
legend('h: Na gate inactivity','m: Na gate activity','n: K gate activity');
title('Ion gate activities');
xlabel('Time (ms)');
ylabel('Activity');
ylim([0 1]);
xlim([-1 20]);
%}

%{
figure;
a=-54;%;%-88.18951%-105;%start (ingerlõ) membrán potenciál
for i=1:15
ySS=[0.3177 0.0530 0.5961 a]; %nyugalmi potenciál, innen indul a rendszer
[t,x]=ode45('hhode',[0 200],ySS); %%HH equation
subplot(2,1,1);
%
if max(x(:,4))>0 && max(x(:,4))<50 % AP
    plot(t, x(:,4),'r')
    drawnow;
    hold on;
    

elseif max(x(:,4))>50 % too high membrane potential
    plot(t, x(:,4),'b')
    drawnow;
    hold on;
    
else
    plot(t, x(:,4),'k') %no AP
    drawnow;
    hold on;
    
end
%format long; a
    title(['Threshold Behavior, voltage: ', num2str(a)]);
    xlabel('Time (ms)');
    ylabel('Transmembrane Voltage (mV)');
    xlim([-1 200]);

subplot(2,1,2);
%iongate activities
plot(t, x(:,3),'r')
hold on
plot(t, x(:,2),'k')
plot(t, x(:,1),'b')
legend('h: Na gate inactivity','m: Na gate activity','n: K gate activity');
title('Ion gate activities');
xlabel('Time (ms)');
ylabel('Activity');
ylim([0 1]);
xlim([-1 200]);
hold off;

waitforbuttonpress;
a=a+2; %az ingerlõ potenciál változtatása (0.0000001); (-53.489254);

end
%}