add up a signal for every timestep

조회 수: 1 (최근 30일)
st
st 2013년 3월 16일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 16일
You want to add the signal to what?
st
st 2013년 3월 16일
I mean i want to sum the wastage after every timestep so that i get the total wastage after the simulation.

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 16일
편집: Azzi Abdelmalek 2013년 3월 16일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 17일
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 2013년 3월 25일
ok, understand that, even so thank you for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by