add up a signal for every timestep

1 Ansicht (letzte 30 Tage)
st
st am 16 Mär. 2013
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 ;)
  2 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 16 Mär. 2013
You want to add the signal to what?
st
st am 16 Mär. 2013
I mean i want to sum the wastage after every timestep so that i get the total wastage after the simulation.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 16 Mär. 2013
Bearbeitet: Azzi Abdelmalek am 16 Mär. 2013
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
  11 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 17 Mär. 2013
st, I can't answer this question, because you did not provide enough information. What is sure is the code I added allows you to do cumulative sum.
st
st am 25 Mär. 2013
ok, understand that, even so thank you for your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by