Here is the full error message:
??? Undefined function or variable "Indicator".
Error in ==> vidya at 44
Indicator(i)=k*sc*Index(i)+(1-k*sc)*Indicator(i+1);
Error in ==> PnL at 22
[Fast] = vidya(Indicator,Shorter_Fast,Longer_Fast);
Error in ==> DEVolSys at 139
Ftemp=OF(data.Indicator,data.Daily_PnL,Pu(1,ii),Pu(4,ii),Pu(2,ii),Pu(5,ii),Pu(3,ii),Pu(6,ii),MinVol);
Error in ==> Optimser at 15
MA_lengths=DEVolSys(de,dataList,@PnL);
Very occasionally I get the error ???Undefined Function or variable Indicator, when the function below is called.
According to the matlab compiler this line is causing the problem
Indicator(i)=k*sc*Index(i)+(1-k*sc)*Indicator(i+1);
It's odd because usually these problems are linked to functions files being stored in the wrong place or variables being used without being initialised.
However, this function is called repeatedly as part of an optimisation scheme and it seems than most of the time it works perfectly but occasionally I get the error above?
It would seem that a problem parameter set may be causing the problem, but I can't understand how a problem parameter set could cause a problem like this? Also with literally thousands of parameters to test each requiring hundreds of steps I need to go through. I'd like to try and get some idea of what might be causing the problem, so if nothing else I know what to look for.
So if anyone can explain what might be causing this kind of problem or a good way to debug such problems it would be great,
function [Indicator] = vidya(Index,Short,Long)
End_Index=1;
Start_Index=size(Index);
if Short>Long
TestVal=Short;
else
TestVal=Long;
end
for i=Start_Index:-1:End_Index
if(i>Start_Index-(TestVal+2))
Indicator(i)=Index(i);
else
Slow=std(Index(i:i+Long-1));
Fast=std(Index(i:i+Short-1));
k=Fast/Slow;
sc=2/(Short+1);
Indicator(i)=k*sc*Index(i)+(1-k*sc)*Indicator(i+1);
end
end
end
created in mutationwhich was probably a comment.Start_Index=size(Index);actually beStart_Index=length(Index);,Start_Index=size(Index,1);, orStart_Index=numel(Index);, etc.? And in the line that causes the error you haveIndicator(i+1)-isialways one less than the number of elements in that array?dbstop if errorbefore running the buggy code, that'll throw you in debug mode next time it errors and you can inspect which variable is missing