clear

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
file_head = 'TanakaFigS7_param'
file_mid1 = '_ratio'
file_mid2 = '_peakCa'
file_tail = '_duration1sec_AMPAR.plot'

AMPARmax = 0.494126;

Ca = 0.0:0.1:10.0;
param = 1; % 1-64
ratio = 2; % 2, 5, 10, 20, 50, 100, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01

for i = 1:101 % Ca2+ peak
    loadtmp = load(strcat(file_head, int2str(param), file_mid1, num2str(ratio), file_mid2, num2str(Ca(i)), file_tail));
    AMPAR = min(loadtmp(:,2));
    LTD(i) = (AMPARmax - AMPAR) / AMPARmax * 100;
end

plot(Ca, LTD, 'LineStyle','-', 'Color','b')
hold on

axis([-0.5 6 -5 40])
set(gca,'Tickdir','out')
box off
set(gca,'xtick',[-0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6])
set(gca,'ytick',[-5 -2.5 0 2.5 5 7.5 10 12.5 15 17.5 20 22.5 25 27.5 30 32.5 35 37.5 40])
set(gca,'XTickLabel','|0||1||2||3||4||5||6')
set(gca,'YTickLabel','-5||0||5||10||15||20||25||30||35||40')
xlabel('[Ca]i (uM)')
ylabel('LTD (%)')
title('Ca-LTD, Parameter Sensitivity')

savefilename = strcat('ParamSensitivity', int2str(param), file_mid1, num2str(ratio), '.txt')
save(savefilename, 'LTD', '-ASCII')