MATLAB: Add up a signal for every timestep

add upsignal

hello i've got an embedded matlab function in my model, which creates an output signal(wastage of fuel). Now i want to add up this signal for every timestep, so that i obtaine the total wastage after the simulation. Is there a way? Hope that was understandable šŸ˜‰

Best Answer

Ok, you want a cumulative sum:
In your embedded function add these codes
at the beginning
function [ā˜ŗutput,cum_output]=fcn(....)
persistent cum_output
if isempty(cum_output)
cum_output=0
end
and at the end of your code
cum_output=cum_output+output
Related Question