How can I change elements in a matrix all at once??

How can I change each element in a matrix so that each new element is for example itself + the element next to it?

답변 (2개)

Jan
Jan 2013년 9월 25일
편집: Jan 2013년 9월 25일

0 개 추천

This seems to be a job for cumsum. A small example would clear the details.
[EDITED] After your comment: NO, not cumsum. See Kelly's answer.

댓글 수: 1

For example if I have mtx = [1 2 3; 4 5 6; 7 8 9] then the new element would be [3 5 3; 9 11 6; 15 17 9] Something like that.

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

Kelly Kearney
Kelly Kearney 2013년 9월 25일

0 개 추천

new = mtx + [mtx(:,2:end) zeros(size(mtx,1),1)]

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by