Summation problem help please!

Hi all!
I am having troubles to do the code for a summation. I tried with two different ways, initializating the variable and then with a loop and with the "sum" function,I'll show you below but I am terribly confused on how to get what I want.
So, I have this matrix, called Snmo, that has 3 dimensions (lets say (29x100x3)) so I picture it as having 3 pages with a matrix of 29x100 in each page and I want to sum the terms in each column of the 29x100 matrix, hence I am collapsing the 29 rows into 1 and the final matrix is 1x100, then I do that for the other two pages, I combine them and the result should be a 3x100 matrix.
Please help!!
Method 1
lp=3
lt=100
Rn(lp,lt)=0;
for lp=1:length(p) %This is the third dimension =3
for lj=1:NXj % rows = 29
for lt=1:length(rec1) &the columns=100
Rn(lp,lt)=Rn(lp,lt) + (Sign(Snmo(lj,lt,lp)).*(abs(Snmo(lj,lt,lp))).^(1/N));
end
end
end
Method 2:
Rn=zeros(9,100);
for i=1:length(p) %3
for j=1:NXj
Rn(i,100)=sum(Sign(Snmo(j,:,i)).*(abs(Snmo(j,:,i))).^(1/N)));
end
end
THANK YOU

댓글 수: 1

A T.
A T. 2012년 12월 5일
you can ignore the "Sign(Snmo(:,:,:)"

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

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2012년 12월 5일

1 개 추천

Would this be what you need?
a=rand(29,100,3);
b=squeeze(sum(a,1));
whos;

댓글 수: 1

A T.
A T. 2012년 12월 5일
Yesss! It's amazing!!
Thank you so much! :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기

제품

태그

질문:

2012년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by