File Exchange

image thumbnail

Moran's I

version (2.53 KB) by Felix Hebeler
Calculates local Moran's I index of spatial correlation for raster.


Updated 31 Mar 2016

View License

PURPOSE: calculate local Moran's I for a local grid using a weight matrix.
USAGE: m = moransI(grid, W, s);
where: [grid] is the matrix to analyze
[W] is the normalized weight matrix of the size the local Moran's I will be calculated for
[s] is an optional flag to use zscores of input values for calculation. Set to 'true' if zscores of local grid should be calculated. Leave blank if not desired or input values are already standardized. -------------------------------------------------------------------------
[m] Moran's I of input raster weighted using [W]
NOTES: Weight matrix needs to be 'moving window' style, not contiguity matrix: Moran's I is calculated and weighted for neighbours to center cell. Matrix needs to be normalized (weights sum to 1) and center cell weight will be set to 0 if not already.
See Anselin (1995, 'LISA.', Geogr. Analysis 27(2),p.93f) for details on standardized variables in calculation of local Moran's I.

Cite As

Felix Hebeler (2020). Moran's I (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Paula Martin

How can you obtain the colormap you show on the main image? How does it relate to the M you get as output?

Thuy-My Le

Hi. Thanks for creating this, but I'm new to spatial indexes. Can you explain what a moving window style matrix is? Thanks.

lei nie

ahmad azizi

soyoung an

This is using wrong method ! it's not about moran's I-_-

Nada Kadhim

Hi Felix,

Thank you for sharing your codes with us.
I have applied on my own image and I got great results. However, in the beginning the code did not work but when I changed the size of window to 3*3 and then it works.

Can Yang

when it run , the result i got is a full matrix with NAN,why ?? does it because the data is too big?? thanks


Thanks for this - I am new to spatial statistics and I need a little help to use this function. I have ~200 latitude and longitude points, and data associated with each point. How do I use this function? Thanks! (Sorry)


on my MATLABR2010B, the Morans function is not available.
What I can do now?
Plz sort out it.

3omyer 3omayer

I would like to calculate the Geary's index for 2 dimension data. the equation is same as the Moran's index but it's not local.
Can you help me please.


Should this function work in one dimension? When I call,

M = morans_I(sourceDataRow,ones(1,3)./3,'true');

I get zeros. When I call,

M = moransI(sourceDataRow,ones(1,3)./3,'true');

I get seemingly correct results, but some values are greater than 1, which should not exist.

Jay Lennard

Ok, but use of confilt or nlfilter would speed up things (would require imageprocessing toolbox)

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

Community Treasure Hunt

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

Start Hunting!