Borrar filtros
Borrar filtros

problem writing a seemingly easy summation

2 visualizaciones (últimos 30 días)
alexaa1989
alexaa1989 el 15 de Ag. de 2014
Comentada: Adam el 15 de Ag. de 2014
hi everyone I have this matrix P and for each column j I need to have a summation from second row to end, or i=2:end
for example
P=[1 3 5 7;3 5 7 9;2 4 6 8];
now the matrix I am looking for is [5 9 13 17]
but no matter how I try to write it the answer is second row only
can someone help?
thank u in advance

Respuesta aceptada

Adam
Adam el 15 de Ag. de 2014
sum( P(2:end,:) )
  4 comentarios
alexaa1989
alexaa1989 el 15 de Ag. de 2014
it just gives 37
Adam
Adam el 15 de Ag. de 2014
Can you paste in the whole Matlab commands with results output to command line? In the answer below you said it gave 34 so it sounds as though something odd is happening with your code or your Matlab.
I get exactly the same as Guillaume posted when I run this command.
sum (and most functions of that type) on a 2d matrix will, by default sum each column and give you a result which is 1-by-numColumns.

Iniciar sesión para comentar.

Más respuestas (1)

Guillaume
Guillaume el 15 de Ag. de 2014
sum(P(2:end, :))
  8 comentarios
alexaa1989
alexaa1989 el 15 de Ag. de 2014
is it possible that I have been using false data???!!!!
alexaa1989
alexaa1989 el 15 de Ag. de 2014
how can i reset MATLAB for update?

Iniciar sesión para comentar.

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