% plotDecayRateFit.m
% Jessica Parker, October 18, 2024
%
% This Matlab script just plots the output from sweepFitDecayRate.m so that you don't have to rerun that sweep fit
% everytime you want to look at and change the plot. This does the same thing as plotMultipleDecayFits.m, but it only
% plots one run5 instance at a time. So just change run5 below to choose which instance you want to plot.
close all;
clear all;
run1 = 4;
run2 = 0;
run3 = 0;
run4 = 2;
run5 = 1;
fitVrsn = 'A';
msrRealVrsn = 'A';
dataDir = 'data/';
figDir = 'plots/';
boltzType = 'h'; % Set to m or h depending on whether it is an activation or inactivation
xmin = 0;
xmax = 15;
VariableYrange = 0; % Set to 1 to have y-range set automatically, set to 0 to use ymin and ymax below
ymin = 0; % This only matters if you set VariableYrange to 0.
ymax = 1; % This only matters if you set VariableYrange to 0.
CloseFigures = 0;
fntnm = 'Lucida Sans';
fntsz = 16;
fntwght = 'bold';
DisplayText = 1;
textYpostn = 0.4;
textXpostn = 0.25;
DullGreen = [155, 196, 114]/255;
fitColor = DullGreen;
textColor = [0 0 0];
dir2 = [num2str(run1) '_' num2str(run2) '_' num2str(run3)];
tmFit = xmin:0.01:xmax;
dir3 = [dir2 '_' num2str(run4)];
dir4 = [dir3 '_' num2str(run5)];
crrntFit = load([dataDir boltzType 'DecayRate' dir4 msrRealVrsn '_' fitVrsn '.txt']); % Loading fit parameters from sweepFitDecayRate.m
current0 = load([dataDir 'tailNormalizedConductance' dir4 msrRealVrsn '.txt']); % Loading tail conductance from measureTailCurrent.m
tm = current0(2,:); % Time points
dcay = current0(1,:); % Normalized conductance values over time
dcay = dcay/max(dcay);
tauX = crrntFit(1); % Decay rate constant of single exponential or first of a double exponential when rtio < 1
tauXb = crrntFit(2); % Decay rate constant of second exponential in the case of double exponential when rtio < 1
rtio = crrntFit(3); % Proportion of double exponential belonging to the first decay rate constant (tauA)
dcayStrt = dcay(1); % Initial normalized conductance at t = 0 right at the peak gNaP, so ideally this will be 1.
dcayEnd = dcay(end); % Final normalized conductance at the end of the trace.
dcayFit = (dcayStrt-dcayEnd)*(rtio*exp(tmFit/tauX)+(1-rtio)*exp(tmFit/tauXb))+dcayEnd; % Fit equation
if VariableYrange
ymin0 = min(dcayFit);
ymax0 = max(dcayFit);
yl0 = ymax0 - ymin0;
ymin = ymin0 - 0.1*yl0;
ymax = ymax0 + 0.1*yl0;
end
yl = ymax - ymin;
f = figure();
f.PaperPositionMode = 'manual';
f.PaperUnits = 'inches';
f.Units = 'inches';
f.OuterPosition = [1 1 6 5];
f.InnerPosition = [0.25 0.25 5.5 4.5];
f.PaperPosition = [0.25 0.25 5 4];
f.RendererMode = 'manual';
axes('position',[0.22 0.19 0.74 0.78]);
hold on;
plot(tm,dcay,'color',[0 0 0],'linewidth',2.5);
plot(tmFit,dcayFit,'--','color',fitColor,'linewidth',2);
if DisplayText
text(xmin+textXpostn*(xmax-xmin),ymin+textYpostn*yl,['\tau_{decay1} = ' num2str(round(abs(tauX),2)) ' s, ' ...
num2str(round(100*rtio)) '%'],'fontsize',fntsz,'fontname',fntnm,'fontweight',fntwght,'color',textColor);
text(xmin+textXpostn*(xmax-xmin),ymin+(textYpostn-0.11)*yl,['\tau_{decay2} = ' num2str(round(abs(tauXb),2)) ...
' s, ' num2str(round(100*(1-rtio))) '%'],'fontsize',fntsz,'fontname',fntnm,'fontweight',fntwght,'color',textColor);
end
ylabel(['<g_{NaP}> (pA)']);
xlabel('Time (s)');
xlim([xmin xmax]);
ylim([ymin ymax]);
yticks([0 0.2 0.4 0.6 0.8 1]);
box off;
ax = gca;
ax.FontName = fntnm;
ax.FontSize = fntsz;
ax.FontWeight = fntwght;
ax.LineWidth = 3.0;
print(f,['plots/decayFits' dir4 msrRealVrsn '_' fitVrsn '.eps'],'-depsc','-r0');
if CloseFigures
close(f);
end