What would be the output from the following program? Think about it, write down your answer, and then type it in to verify
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:23.6
All Answers
total answers (1)
testscope.m
answer = 5;
fprintf('Answer is %d\n',answer)
pracfn
pracfn
fprintf('Answer is %d\n',answer)
printstuff
fprintf('Answer is %d\n',answer)
pracfn.m
function pracfn
persistent count
if isempty(count)
count = 0;
end
count = count + 1;
fprintf('This function has been called %d times.\n',count)
end
printstuff.m
function printstuff
answer = 33;
fprintf('Answer is %d\n',answer)
pracfn
fprintf('Answer is %d\n',answer)
end
>> testscope
Answer is 5
This function has been called 1 times.
This function has been called 2 times.
Answer is 5
Answer is 33
This function has been called 3 times.
Answer is 33
Answer is 5
>>
need an explanation for this answer? contact us directly to get an explanation for this answer