MATLAB Answers

Double summation of a matrix

13 views (last 30 days)
Psk
Psk on 22 Oct 2020
Answered: Matt J on 22 Oct 2020
How to implement the summation? I am not able to do this.

  0 Comments

Sign in to comment.

Answers (2)

Matt J
Matt J on 22 Oct 2020
In recent Matlab, you can do
sum(matrix,'all')
or more generally you can do
sum(matrix(:))

  3 Comments

Psk
Psk on 22 Oct 2020
Then how will i specify the limits for summation?
Rik
Rik on 22 Oct 2020
Just an addition: Since R2018b you can use the S = sum(A,vecdim) syntax. So if you happen to have a 3D array and want to sum only rows and columns you can use this:
sum(matrix,[1 2])
Matt J
Matt J on 22 Oct 2020
Then how will i specify the limits for summation?
You can extract the appropriate sub-matrix by indexing it, e.g.,
A=rand(10);
sum(A(1:5,2:7),'all')
ans = 14.8419

Sign in to comment.


Matt J
Matt J on 22 Oct 2020
The expression in your .jpg file, if it needs to be evaulated for all p,q would be
SML=conv2(ML,ones(N+1),'same')

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!