MATLAB: Output argument “PulsTijd” (and maybe others) not assigned during call to (location)

erroroutput argumentvariable

I use this function in 2 independent scripts. In the first it works without a problem. When I adress it in a second (seperated) script, it gives the error:
Output argument "PulsTijd" (and maybe others) not assigned during call to (location). I read other threats about this topic without result.
What is the way to resolve this problem please?
function[Pulsen,VerlopenTijd,Totaal,PulsTijd] = PulsenTeller(Data,TijdArray,Start,Einde)
Totaal = ones(1,length(TijdArray))-1;
Pulsen = 0;
Q = 0;
NietInPuls = true;
Tijd = 0;
PulsGevonden = false;
DrempelVoltage = 5;
for i=Start:Einde
if i > Start
Totaal(i) = Totaal(i-1);
end
if (Data(i)>DrempelVoltage) && NietInPuls
NietInPuls = false;
if PulsGevonden
Tijd = TijdArray(i)- TijdStart;
Pulsen = Pulsen + 1;
Totaal(i) = Totaal(i)+1;
else
TijdStart = TijdArray(i);
Totaal(i) = 0;
Pulsen = 0;
end
PulsGevonden = true;
elseif Data(i) <= DrempelVoltage
NietInPuls = true;
end
end
for i=Einde:length(Data)
Totaal(i)=Totaal(Einde);
end
PulsNummer=1;
InPuls=false;
PulsGevonden=false;
for i=Start:Einde
if i > Start
Totaal(i) = Totaal(i-1);
end
if Data(i)>DrempelVoltage
InPuls=true;
else if(Data(i)<DrempelVoltage) && InPuls
InPuls=false;
if PulsGevonden
PulsNummer=PulsNummer+1;
BeginTijd(PulsNummer)= TijdArray(i);
PulsTijd(PulsNummer)= BeginTijd(PulsNummer)-BeginTijd(PulsNummer-1);
else
BeginTijd(PulsNummer)=TijdArray(i);
PulsNummer=1;
end
PulsGevonden=true;
end
end
end
VerlopenTijd = Tijd;

Best Answer

Your output arguments are Pulsen,VerlopenTijd,Totaal,PulsTijd. However, you only initialized Pulsen and Totaal. Initialize everything first:
Totaal = ones(1,length(TijdArray))-1;
Pulsen = 0;
VerlopenTijd = 0; % Whatever....

PulsTijd = 0; % Whatever....
Then at least they will have SOME value whenever your function returns. Then use this link to step through your code and figure out why PulsTijd never got assigned.
Also see this link so that you can format your posts porperly.
Related Question