Simple question about sum function
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 9 Mär. 2015
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.
Antworten (2)
Adam
am 9 Mär. 2015
X = 1:10
Y = X + 1;
sumRes = sum( Y );
for e.g. X from 1 to 10
2 Kommentare
Adam
am 9 Mär. 2015
Bearbeitet: Adam
am 9 Mär. 2015
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
am 9 Mär. 2015
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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!