File Exchange

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

version 1.4.0.0 (10.9 KB) by David J. Mack

David J. Mack (view profile)

Compute a moving correlation for two vectors x & y in analogy to the MOV* functions.

Updated 14 Dec 2017

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

David J. Mack

David J. Mack (view profile)

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

li Ming (view profile)

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)

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.

David J. Mack

David J. Mack (view profile)

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

li Ming (view profile)

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.

 14 Dec 2017 1.4.0.0 [MOD] - Now returns NaN for zero-variances, to be consistent with CORR. 14 Dec 2017 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. 11 Dec 2017 1.2.0.0 Fix in input parser. 11 Dec 2017 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. 7 Dec 2017 1.1.0.0 Forgot file update 7 Dec 2017 1.1.0.0 Computation of r with NaNs + omitnan flag now gives same results as CORR(...,'Rows','pairwise'). 7 Dec 2017 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