필터 지우기
필터 지우기

problem writing a seemingly easy summation

조회 수: 2 (최근 30일)
alexaa1989
alexaa1989 2014년 8월 15일
댓글: Adam 2014년 8월 15일
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

채택된 답변

Adam
Adam 2014년 8월 15일
sum( P(2:end,:) )
  댓글 수: 4
alexaa1989
alexaa1989 2014년 8월 15일
it just gives 37
Adam
Adam 2014년 8월 15일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2014년 8월 15일
sum(P(2:end, :))
  댓글 수: 8
alexaa1989
alexaa1989 2014년 8월 15일
is it possible that I have been using false data???!!!!
alexaa1989
alexaa1989 2014년 8월 15일
how can i reset MATLAB for update?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by