Output argument "PulsTijd" (and maybe others) not assigned during call to (location)

10 views (last 30 days)
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;

Accepted Answer

Image Analyst
Image Analyst on 9 Apr 2015
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.

More Answers (1)

Thomas Koelen
Thomas Koelen on 9 Apr 2015
Explanation:
One of the functions you have called is defined to return an output argument but that output argument does not exist in the function when it tries to return.
Common causes:
You have misspelled the name of one of your output arguments inside your function, or you have forgotten to assign a value to one of the output arguments of your function. Alternatively, the function was originally written with one or more output arguments, but the section of the function that computed the output argument was removed or modified in such a way that the output argument is now extraneous.
Solution:
Stop MATLAB on the last line of the function listed in the warning or error message. Verify that each of the output arguments listed in the function declaration line at the beginning of the function exist after that last line is executed (using the DBSTEP function or the Step button in the Editor). If the arguments do not exist, examine the function to determine where you intended the arguments to be declared. Verify that those lines of code are being executed and have no typographical errors.

Categories

Find more on Scripts in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!