MATLAB: Persistent fileSeparator while calling function in a script

fileseparatorfullfilefunctions in scriptindexing

I wrote the script that calls few functions, they were written in order to optimize work of the script. My error is
Trabalho1
NaN/Inf breakpoint hit for fullfile.p on line 28.
29 persistent fileSeparator;
it occurs in line
alfan(i) = an(vm(i));
that calls function 'an' using vm(i) as input. I don't use fullfile and I don't understand why it happens. All files are in the same folder, my working directory.
Full code:
%%Input dado pelo usuário
prompt = {'Insira o valor da corrente de estímulo Is (em unidades de mA/cm^2):','Insira o valor do tempo total T (em unidades de ms):','Insira o valor do tempo do início da estimulaçao (em unidades de ms):','Insira o valor da duracao do estimulo (em unidades de ms):','Insira o tamanho do passo temporal (em unidades de ms):','Insira o valor da temperatura (em unidades de C):'};
dlg_title = 'Estímulo';
num_lines = 1;
answer = inputdlg(prompt,dlg_title,num_lines);
Is = str2double(answer{1}); % um corrente de estímulo Is [mA/cm^2]

T = str2double(answer{2}); % tempo total [ms]

ti = str2double(answer{3}); % inicio [ms]

td = str2double(answer{4}); % duracao [ms]

dt = str2double(answer{5}); %[ms]


TC = str2double(answer{6}); % temperatura [C]
% O ciclo para testar os limites das variaveis da entrada
while(1)
if (Is < 0) || ((ti+td)>T) || (T<30)
prompt = {'Insira o valor da corrente de estímulo Is (em unidades de mA/cm^2):','Insira o valor do tempo total T (em unidades de ms):','Insira o valor do tempo do início da estimulaçao (em unidades de ms):','Insira o valor da duracao do estimulo (em unidades de ms):','Insira o tamanho do passo temporal (em unidades de ms):','Insira o valor da temperatura (em unidades de C):'};
dlg_title = 'Estímulo';
num_lines = 1;
answer = inputdlg(prompt,dlg_title,num_lines);
Is = str2double(answer{1}); % um corrente de estímulo Is [mA/cm^2]
T = str2double(answer{2}); % tempo total [ms]
ti = str2double(answer{3}); % inicio [ms]
td = str2double(answer{4}); % duracao [ms]
dt = str2double(answer{5}); %[ms]
TC = str2double(answer{6}); % inicio [C]
else
break;
end
end
%%Cálculos
% tempo
% y = linspace(x1,x2,n) generates n points. The spacing between the points is dt = (T-0)/(np-1).
np = (T/dt)+1; %number of iterations
t = linspace(0,T,np); %[ms]
% pontos do inicio e fim
npi = ti*(1/dt);
tf = ti + td;
npf = tf*(1/dt);
% Potenciais de Nernst

[ EK, ENa, EL ] = nernst( TC );
% Condutancias
gK = zeros(1,np);
gNa = zeros(1,np);
% Correntes [uA/cm^2]
Im = zeros(1,np);
IK = zeros(1,np);
INa = zeros(1,np);
IL = zeros(1,np);
Ii = zeros(1,np);
Ic = zeros(1,np);
% Potenciais [mV]
Vm = zeros(1,np);
dVm = zeros(1,np);
vm = zeros(1,np);
% Alfas e betas [ms^-1]
alfan = zeros(1,np);
betan = zeros(1,np);
alfam = zeros(1,np);
betam = zeros(1,np);
alfah = zeros(1,np);
betah = zeros(1,np);
% probabilidades

dn = zeros(1,np);
dm = zeros(1,np);
dh = zeros(1,np);
n = zeros(1,np);
m = zeros(1,np);
h = zeros(1,np);
% constantes
Vr = 60.0; %[mV]
Cm = 0.001; %[mF/cm^2]
gKmax = 36.0; %[mS/cm^2]



gNamax = 120.0; %[mS/cm^2]
gL = 0.3; %[mS/cm^2]
dbstop if naninf
for i = 1:np
if (i <= npi) || (i >= npf) %antes e depois de estimulacao
%Potenciais
Vm(i)= -60.0;
vm(i) = Vm(i) - Vr;
%condutanciais
gK = 0.367;
gNa = 0.011;
% probabilidades
n(i) = 0.31768;
m(i) = 0.05293;
h(i) = 0.59612;
% inicio
if i==npi
Im(i)= Is;
dVm(i) = dt*(Is/Cm);
Vm(i) = Vm(i-1) + dVm(i);
vm(i) = Vm(i) - Vr;
else
Im(i)= 0;
end
else
% corrente transmembranar
Im(i) = Is;
%potencial de membrana
dVm(i)= (dt/Cm)*(Im(i-1)-Ii(i-1));
Vm(i) = Vm(i-1) + dVm(i);
vm(i) = Vm(i) - Vr;
%alfas e betas
alfan(i) = an(vm(i));
betan(i) = 0.125*exp(-vm(i)/80);
alfam(i) = am(vm(i));
betam(i) = 4*exp(-vm(i)/18);
alfah(i) = 0.07*exp(-vm(i)/20);
betah(i) = 1/(exp((30-vm(i))/10)+1);
%n, m, h

dn(i) = dt*(alfan(i)*(1-n(i-1)) - betan(i)*n(i-1));
dm(i) = dt*(alfam(i)*(1-m(i-1)) - betam(i)*m(i-1));
dh(i) = dt*(alfah(i)*(1-h(i-1)) - betah(i)*h(i-1));
n(i)= n(i-1)+dn(i);
m(i)= m(i-1)+dm(i);
h(i)= h(i-1)+dh(i);
%condutancias [mS/cm^2]
gNa(i) = gNamax*(m(i)^3)*h(i); %[mS/cm^2]
gK(i) = gKmax*(n(i)^4);
% Potenciais de Nernst
% correntes ionicas %[uA/cm^2]
INa(i)= gNa(i)*(Vm(i)-ENa);
IK(i) = gK(i)*(Vm(i)-EK);
IL(i) = gL*(Vm(i)-EL);
Ii(i) = IK(i) + INa(i) + IL(i);
% corrente capacitiva [uA/cm^2]
Ic(i) = Cm*(dVm(i)/dt);
end
end
%%Gráficos
figure(1)
%Im
subplot(2,3,1)
plot(t,Im)
xlabel('Tempo','FontSize',12);
ylabel('Corrente transmembranar [mA/cm^2]','FontSize',12);
%INa, IK
subplot(2,3,2)
plot(t,INa,t,IK)
xlabel('Tempo','FontSize',12);
ylabel('Correntes ionicas [mA/cm^2]','FontSize',12);
legend('corrente do sodio','corrente do potassio');
%gNa, gK
subplot(2,3,3)
plot(t,gNa,t,gK)
xlabel('Tempo','FontSize',12);
ylabel('Condutancias do potassio e sodio [mS/cm^2]','FontSize',12);
legend('condutancia do sodio','condutancia do potassio');
%Vm
subplot(2,3,4)
plot(t,Vm)
xlabel('Tempo','FontSize',12);
ylabel('Potencial da membrana [mV]','FontSize',12);
%n, m, h
subplot(2,3,5)
plot(t,n,t,m,t,h)
xlabel('Tempo','FontSize',12);
ylabel('Gating','FontSize',12);
legend('n','m','h');
function [ alfan ] = an( vm )
if vm == 10
alfan = 0.1;
else
alfan = (0.01*(10-vm))/(exp((10-vm)/10)-1);
end
end
function [ alfam ] = am(vm)
if vm == 25
alfam = 1;
else
alfam = (0.1*(25-vm)/(exp((25-vm)/10)-1));
end
end
MATLAB R2015a Thank you in advance.

Best Answer

I do not have that version of MATLAB, so I am going to have to speculate here.
That line calling an() happens to be the first function call in your code after your "dbstop if naninf". The call might have nothing to do with the content of the function, and might instead have to do with the fact that you are calling some function and MATLAB has to process it internally as part of the calling sequence. The internal processing could conceivably involve calling fullfile() as part of putting together the internal descriptor of the Just In Time compiled code, such as would be done as part of building the information used by the information routine functions().
Now it could be that for some reason the internal processing for fullfile sets the persistent variable named fileSeparator to either NaN or Inf, and that NaN or inf value is detected when the "persistent" statement brings the old value back into use.
The R2014a code for fullfile() is a .m file that does not use a variable by that name, but I have no information about R2015a and fullfile.p
A way to test this would be to start at the command line, give the dbstop command and then deliberately call fullfile('A', 'B') and see if it gets stopped in the debugger.
Unfortunately dbstop does not allow you to confine the effect of "dbstop if naninf" to a particular file so if fullfile() has this behaviour working around it might be tricky.
It is possible that the fullfile() does not get called by MATLAB until it is putting together the debugging message for a nan or inf within an() -- you could dbcont and see whether you get a clean breakpoint in an(). It might even only handle the first time the routine is called... I don't know.