Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

i want to sum each row of a matrix to the next row of the same matrix and save it in a new variable. its a part of big algorithm.

조회 수: 1 (최근 30일)
let the matrix is this
A= [1 2 3 4; 5 6 7 8; 4 3 2 1];
and i want to get this
X=[1 2 3 4; 6 8 10 12; 10 11 12 13];
thanks in advance...

답변 (2개)

Walter Roberson
Walter Roberson 2020년 1월 23일
cumsum(A, 1)

Sheharyar Mr
Sheharyar Mr 2020년 1월 23일
its working. can we do this from nested loop.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 1월 23일
Yes, you can call cumsum inside of loops.
Perhaps what you are looking for is something like
C(k+1,:) = C(k, :) + A(k+1, :)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by