Simple question about sum function

조회 수: 5 (최근 30일)
Hoheok Kim
Hoheok Kim 2015년 3월 9일
답변: Michael Haderlein 2015년 3월 9일
Hello. I am a new beginner of MATLAB. I have a simple question about sum function. With above functions,for input cmo(1), the answer is output=aaa E=bbb. For cmo(2), the answer is output=ccc and E=ddd What I want to know is the sum of E when i=1~196 Is there any way that I can get sum of E??
  댓글 수: 1
Jan
Jan 2015년 3월 9일
A strange question. "With above functions"? Which functions? What is "cmo(1)" and what does "output=aaa E=bbb" mean??? What is "1~199"? "~" is the not() operator and there meaningless here. So I do not understand any sentence of this question. Please be much more specific and post the relevant code.

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

답변 (2개)

Adam
Adam 2015년 3월 9일
X = 1:10
Y = X + 1;
sumRes = sum( Y );
for e.g. X from 1 to 10
  댓글 수: 2
Hoheok Kim
Hoheok Kim 2015년 3월 9일
Thank you for your answer. But that was what I wanted. I changed my question more specifically. could you answer my question again?
Adam
Adam 2015년 3월 9일
편집: Adam 2015년 3월 9일
You shouldn't really change a question so dramatically after people have already answered it. If you want to ask a completely different question then start a new thread. If you want to amend or clarify your question that is fine too of course, but if you change the entire question after people have answered those answers become completely irrelevant for anyone else looking into the thread.
Your original question lived up to your "I have a simple question", but your edited version does not seem to make any sense.

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


Michael Haderlein
Michael Haderlein 2015년 3월 9일
I don't know cmo, so I can only guess. If it is possible to vectorize the function, then you will get all outputs at once and can simply sum up, like
[output E]=cmo(1:196);
sumE=sum(E);
In case this is not possible, you need such a loop:
>> for cnt=1:10
[output EEE(cnt)]=max(max(magic(cnt)));
end
>> EEE
EEE =
1 1 2 1 3 2 4 1 5 3
>> sum(EEE)
ans =
23
This max(max(magic())) function is the placeholder for cmo here. You see that it returns all EEE(cnt). You can sum up them, again. In case EEE is an array, you need to use EEE(:,cnt) or EEE(cnt,:), respectively (also you need to define the summation direction, then).

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by