Borrar filtros
Borrar filtros

Simple question about sum function

1 visualización (últimos 30 días)
Hoheok Kim
Hoheok Kim el 9 de Mzo. de 2015
Respondida: Michael Haderlein el 9 de Mzo. de 2015
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 comentario
Jan
Jan el 9 de Mzo. de 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.

Iniciar sesión para comentar.

Respuestas (2)

Adam
Adam el 9 de Mzo. de 2015
X = 1:10
Y = X + 1;
sumRes = sum( Y );
for e.g. X from 1 to 10
  2 comentarios
Hoheok Kim
Hoheok Kim el 9 de Mzo. de 2015
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 el 9 de Mzo. de 2015
Editada: Adam el 9 de Mzo. de 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.

Iniciar sesión para comentar.


Michael Haderlein
Michael Haderlein el 9 de Mzo. de 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).

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by