MATLAB Answers

How to calculate reveral summations

52 views (last 30 days)
Xuefei Sun
Xuefei Sun on 23 Feb 2021
Edited: Matt J on 25 Feb 2021
I need to calculate sigma=sum(u(t)*u(t+a)), from a to 600(t=a to 600), and a is from 1 to 600. So I should get 600 different sigma.
How to do it?
  3 Comments
Xuefei Sun
Xuefei Sun on 24 Feb 2021
Sorry, the "h" should be a.
The data is u. For example u1 to u1500. And when a=1, I will get sigma(1)=u1*u(1+1)+u(2)*u(2+1)+...u(600)*u(600+1), and then a=2, I will get sigma(2)=u2*u(2+2)+u(3)*u(3+2)+...u(600)*u(600+2). ... a=600, sigma(600)=u600*u(600+600)

Sign in to comment.

Answers (2)

Matt J
Matt J on 23 Feb 2021
Use conv() or xcorr().
  8 Comments
Xuefei Sun
Xuefei Sun on 24 Feb 2021
Yes, I think that is my problem, since my u data is 600x1, my y data is also 600x1. Both of them are Vrctors.
So how to fix it?

Sign in to comment.


Matt J
Matt J on 24 Feb 2021
Edited: Matt J on 24 Feb 2021
T=triu(ones(600));
I=(1:600).' + (1:600);
ur=u(:).';
sigma= (T.*ur(I))*ur(1:600).';
  2 Comments
Matt J
Matt J on 25 Feb 2021
Works fine when I run it.
u=rand(1,1500); %Example data
T=triu(ones(600));
I=(1:600).' + (1:600);
ur=u(:).';
sigma= (T.*ur(I))*ur(1:600).';
whos sigma
Name Size Bytes Class Attributes sigma 600x1 4800 double

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!