Computing summation in matlab

I have a matrix let say A=ones(144,40);
and I want to compute the summation with lower limit is 1 and upper limit is dimension of A like 144*40=5760.
How can I compute it using symsum or sum other function?

답변 (2개)

Wayne King
Wayne King 2013년 2월 22일
편집: Wayne King 2013년 2월 22일

0 개 추천

A = ones(144,40);
B = sum(A(:));
or
B = sum(sum(A));
Mark Whirdy
Mark Whirdy 2013년 2월 22일
편집: Mark Whirdy 2013년 2월 22일

0 개 추천

If Wayne is right and you're talking about limits to the summation, is it that you want to control these limits as parameters, or you simply want to always sum over every element (1:(size(A,1)*size(A,2))) of the matrix?
Wayne provides the latter solution, a solution to the former might be
limitSum = @(X,l_b,u_b)(sum(X(l_b:u_b))); % define amonymous function
A = ones(144,40);
limitSum(A,1,size(A,1)*size(A,2)); % apply function to A

댓글 수: 5

Wayne King
Wayne King 2013년 2월 22일
I think the OP is just referring to the limits of the summation as in
\sum_{n=1}^{N} x[n]
No...it mean when we compute summation this is a lower and upper limit
5760
like SUM(A).where is matrix of size 144x40.
1
Thanks...any help plz
Algorithms Analyst
Algorithms Analyst 2013년 2월 22일
where A is matrix of size 144x40
Wayne King
Wayne King 2013년 2월 22일
did you look at my answer? that sums all the elements in the matrix
Mark Whirdy
Mark Whirdy 2013년 2월 22일
then its just a sum as Wayne said

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

카테고리

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

질문:

2013년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by