Simple question about sum function

1 次查看(过去 30 天)
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
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 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by