simple correlation of two input.. Please Help.. :) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

simple correlation of two input.. Please Help.. :)

benjaminganbenjamingan Posts: 1Member
Hi all,
I'm trying to perform a simple correlation when the input is:

a=[1 2 3 4 5]
b=[1 2 3 4 5 6 7 8 9 10]

i've tried by using hand calculation, the answer is
[55 70 85 100 115]

below are the code that i've tried in matlab:

a=[1 2 3 4 5];
b=[1 2 3 4 5 6 7 8 9 10];
n=lenght(a);

i=1:n;
R(i)=a(i).*b(i)
sum (R(i))

for i2=1:1:n;
k=i2+1:n+i2;
R(i)=a(i).*b(k);
R(i)
sum (R(i))

end

but once if i change the input to:
a=[1 2 3 4 5];
b=[1 2 3 4 5];

the answer should be
[5 14 26 40 55]

but unfortunately,an error occurs as shown below:

??? Index exceeds matrix dimensions.

Error in ==> loop5 at 14
R(i)=a(i).*b(k);

unless if i change b=[1 2 3 4 5 0 0 0 0 0];

can anyone please tell me what should i do and what went wrong?
thank you all very much for helping.. :)

Ben




Sign In or Register to comment.