Write a function per2 that receives one number as an input argument. The function has a persistent variable that sums the values passed to it. Here are the first two times the function is called:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:22.6
All Answers
total answers (1)
per2.m
function outstat = per2(num)
% Persistent variable sums the numbers
% passed to this function
% Format of call: per2(input number)
% Returns the persistent sum of input arguments
persistent mysum
if isempty(mysum)
mysum = 0;
end
mysum = mysum + num;
outstat = mysum;
end
need an explanation for this answer? contact us directly to get an explanation for this answer