I have matrix A, how can I add a row in matrix A with others rows of matrix A ?

조회 수: 2 (최근 30일)
I have matrix A, how can I add a row in matrix A with others rows of matrix A ?
For example:
a = ones (220,220);
b = a(:,1)+a(:,11)+a(:,21)+ a(:,31)+a(:,41)+a(:,51)+a(:,61)+a(:,71)+a(:,81)+a(:,91);
I would like to obtain sum of row as b. The problem is the matrix I'm working on is thousands, is there a more easy way to do this? a certain function maybe that only needs me to specify the column number. Thank you!

채택된 답변

Matt Kindig
Matt Kindig 2013년 5월 29일
b = sum(a(:,1:10:91),2)
  댓글 수: 2
Firzi Mukhri
Firzi Mukhri 2013년 5월 29일
it works! but what is the number 2 represent?
Matt Kindig
Matt Kindig 2013년 5월 29일
2 is the dimension over which the summing is performed. Dimensions are ordered in the same order that they are returned from the size() function, i.e. dimension=1 is sum down the rows, dimension=2 is sum down the columns, dimension=3 is sum across dimension 3 ("planes"), etc.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by