Assume a matrix variable mat, as in the following example:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:24.6
All Answers
total answers (1)
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:24.6
total answers (1)
sumprint.m
function sumprint(vec)
% Prints the result of a persistent sum
% of the values in vectors that are passed
% Format of call: sumprint(vector)
% Returns the persistent sum of all input vectors
persistent mysum
if isempty(mysum)
mysum = 0;
end
mysum = mysum + sum(vec);
fprintf('The sum is now %d\n', mysum)
end
need an explanation for this answer? contact us directly to get an explanation for this answer