sum of values in column wise

조회 수: 492 (최근 30일)
Azza Ahmed
Azza Ahmed 2012년 7월 25일
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

답변 (1개)

Albert Yam
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
  댓글 수: 1
Azza Ahmed
Azza Ahmed 2012년 7월 30일
Many thanks Albert for helping in this!
Cheers
AA

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

카테고리

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