Simple question about sum function
6 ビュー (過去 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
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
2015 年 3 月 9 日
X = 1:10
Y = X + 1;
sumRes = sum( Y );
for e.g. X from 1 to 10
2 件のコメント
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
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).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!