File Exchange

image thumbnail

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

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


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

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. 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.


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

- 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.

Fix in input parser.

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

Forgot file update

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

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