Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.