corrcoef - vectors of different lengths

23 vues (au cours des 30 derniers jours)
Richard
Richard le 2 Avr 2012
How is it possible to find the correlation between vectors of different lengths? For example:
clear all
time1 = 1 + (365-1).*rand(1,12);
time2 = 1 + (365-1).*rand(1,24);
data1 = 1 + (20-1).*rand(1,12);
data2 = 1 + (20-1).*rand(1,24);
usually I would find the correlation with:
R = corrcoef(data1,data2);
but the vectors need to be the same lengths! How would I achieve this?

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 2 Avr 2012
try use function interp1
eg
data1 = 1 + (20-1).*rand(1,12);
data2 = 1 + (20-1).*rand(1,24);
d2 = interp1(1:numel(data1),data1,linspace(1,numel(data1),numel(data2)));
R = corrcoef(d2,data2)
OR
d2 = data2(1:2:end)
R = corrcoef(data1,d2)
  2 commentaires
Richard
Richard le 2 Avr 2012
with the first method mentioned, does this basically just make data1 into 24 points instead of 12?
Andrei Bobrov
Andrei Bobrov le 2 Avr 2012
yes

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by