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

1 回表示 (過去 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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by