sum of values in column wise
511 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am trying to add values in a matrix that each is identified as I(x,y) where each of x and y is 3*3 matrix. Now, what I need to do is to sum these values in column wise and put them into a new matrix of 1*3. For example, I want to add I(x1,y1)+I(x2,y1)+I(x3,y1) and put it in first column of the new matrix. Then add I(x1,y2)+I(x2,y2)+I(x3,y2) and put this value on the second column of the new martix while keeping the number of row of the other matrix the same...and so on.
I tried to use sum(I(x,y)) with a for loop for x=1:3 while keeping the y constant and later increment the y, but this doesn't seem to work with me.
Can anyone help me with this please?
All the best
AA
0 件のコメント
回答 (1 件)
Albert Yam
2012 年 7 月 25 日
B = sum(A,dim) sums along the dimension of A specified by scalar dim. The dim input is an integer value from 1 to N, where N is the number of dimensions in A. Set dim to 1 to compute the sum of each column, 2 to sum rows, etc.
test = rand(3);
ans = sum(test,1) % sum along dimension 1
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!