File Exchange

image thumbnail

movcorr(x, y, k, varargin): Compute windowed correlation coefficient

version 1.4.0.0 (10.9 KB) by David J. Mack
Compute a moving correlation for two vectors x & y in analogy to the MOV* functions.

23 Downloads

Updated 14 Dec 2017

View License

Computes the Pearson product-moment correlation coefficient r over a moving window for two vectors x & y. This is
basically a wrapper to MOVSUM and the low-memory overhead computation of r. See second formula in
https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#For_a_sample

Comments and Ratings (4)

Hey Li Ming,
the input parser has changed its syntax and that's why it does not work with your version of ML... too bad.

li Ming

Thanks for your kindly reply. when l run [r, p] = movcorr(rand(100,1), rand(100,1), 11) in Maltalb 2011b, some errors occur as follows:

No appropriate method, property, or field addParameter for class inputParser.

Error in movcorr>parseInputs (line 217)
IP.addParameter('Endpoints', VALID_ENDPNTS{1}, validateCharOrNumRow);

Error in movcorr (line 107)
[x, y, k, missing, endpoints, tail, nMin, n] ...

will it be the matter of the matlab version l used? Thanks again.

Hey Li Ming!
Could you specify what exactly is not working? The syntax resembles the syntax of the built-in MOV* functions (e.g. https://ch.mathworks.com/help/matlab/ref/movmedian.html) as closely as possible. So a toy example would be
[r, p] = movcorr(rand(100,1), rand(100,1), 11)
Hope that helps.

li Ming

specify the vector x and y, and specify a Positive integer scalar, but r = MOVCORR(x, y, k) doesn't work. Could you give some examples? Thanks a lot.

Updates

1.4.0.0

[MOD]
- Now returns NaN for zero-variances, to be consistent with CORR.

1.3.0.0

[ADD]
- Output n to return the local window sizes (useful for computing partial correlations).
- Name-value input 'MinN' to control how many samples are needed in a local window to compute r.

1.2.0.0

Fix in input parser.

1.2.0.0

[ADD]
- Name-value input 'Tail' and according p-value output.
[MOD]
- Now uses INPUTPARSER. Changes error messages for invalid inputs.
[FIX]
- Erroneous window size computation when using k = [nB, nF].
- Complex output when using numeric endpoints.

1.1.0.0

Forgot file update

1.1.0.0

Computation of r with NaNs + omitnan flag now gives same results as CORR(...,'Rows','pairwise').

1.0.0.0

Added ML-FEX ID to description.

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor