How to calculate the correlation functions for two vectors which have three components for each part

조회 수: 5 (최근 30일)
Hi every one I write my own code to calculate the correlation function for two vectors (A and B) which have 3 columns (A1(t),A2(t),A3(t) and B1(t),B2(t),B3(t)).But it takes long time to run. So I want to use Matlab inbuilt functions to do it. What I want is Corr(1)=(A1(t2)*B1(t1)+A2(t2)*B2(t1)+A3(t2)*B3(t1))+(A1(t3)*B1(t2)+A2(t3)*B2(t2)+A3(t3)*B2(t2)).......(A1(tn-1)*B1(tn)+A2(tn-1)*B2(tn)+A3(tn-1)*B3(tn))
For the Corr(2) and so on, just shift the time.
I have looked at the xcorr function,it can not achieve what I want.
Any suggestions?

답변 (1개)

Karen Pearson
Karen Pearson 2018년 2월 21일
It is not clear what you are trying to achieve. Do you have two vectors of time-based values, A=(a1, a2, a3) and B=(b1, b2, b3) in which time increments between each value? xcorr should work fine for that. Do you actually have two matrices of values - as above, but where each a1, a2, etc. is itself a vector of time-based values? In that case you need to determine if you only want to correlate a1 with b1, a2 with b2, and a3 with b3, which can be done individually with xcorr. If you want a complete two dimensional correlation also correlating vector a1 with b2 etc., then use xcorr2 but that is much more intensive so I wouldn't recommend it if you don't need the extra dimension. There's certainly no need to write your own correlation functions with what Matlab has built in.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by