Difference between the usage of sum functions

Hey, can someone explain, why the results are different? And which way is the right one? Thanks.
X=A+B+C-D;
Sum1=sum(X)
Sum2=sum(A)+sum(B)+sum(C)-sum(D)

 Respuesta aceptada

madhan ravi
madhan ravi el 17 de Oct. de 2018

0 votos

SUM1 is the right one.
It calculates your resultant matrix’s sum
But the latter calculates the sum o each matrices and does the arithmetic operations but then also it depends on your wish.

2 comentarios

Benedikt Wessel
Benedikt Wessel el 17 de Oct. de 2018
Thanks!
madhan ravi
madhan ravi el 17 de Oct. de 2018
Editada: madhan ravi el 17 de Oct. de 2018
you’re welcome you can also vote for the answer

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 17 de Oct. de 2018

Editada:

el 17 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by