SPATIALCORRELATIONSIGNIFICANCEEstimatesignificanceofcorrelationbetweentwospatialindexmapsThisfunctionestimatesthesignificanceofcorrelationbetweentwospatialindexmaps(indexAandindexB)whileaccountingforspatialautocorrelation.Itusestoroidalshifts(randomX/Yoffsets)ofindexBtocreateanulldistributionofcorrelationvaluesthatpreservesthespatialstructureofthedata.Syntax:[p,r_observed,r_null_distribution]=spatialCorrelationSignificance(indexA,indexB)[p,r_observed,r_null_distribution]=spatialCorrelationSignificance(indexA,indexB,options)Inputs:indexA-2Dmatrixcontainingthefirstindexvalues(e.g.,responsetostimulusA)indexB-2Dmatrixcontainingthesecondindexvalues(e.g.,responsetostimulusB)options-Structurewithoptionalparameters:.mask-Logical2Dmatrixspecifyingpixelstoinclude(default:allpixels).n_permutations-Numberofrandomtoroidalshiftstoperform(default:1000).max_shift-Maximumallowedshiftinpixels(default:size(indexA)/2).alpha-Significancelevel(default:0.05).plot_results-Logicalflagtogeneratesummaryplot(default:false)Outputs:p-p-valuefortheobservedcorrelationr_observed-ObservedcorrelationcoefficientbetweenindexAandindexBr_null_distribution-VectorofcorrelationvaluesfromthenulldistributionExample:% Generate sample dataindexA=randn(50,50);indexB=indexA*0.3+randn(50,50)*0.9;% Related but noisy% Set optionsplot_results=true;n_permutations=2000;% Increase number of permutationsmask=indexA>-1;% Example: custom mask based on data values% Estimate significance[p,r_obs,r_null]=spatialCorrelationSignificance(indexA,indexB,...'plot_results',plot_results,'n_permutations',n_permutations,...'mask',mask);fprintf('Observed correlation: %.3f, p-value: %.3f\n',r_obs,p);Notes:-Bothindexmapsmustbethesamesize-Thefunctionusestoroidalshifts(wrappingaroundedges)tomaintainthespatialautocorrelationstructureinthepermutationtest-NaNvaluesineitherindexmapwillbeexcludedfromanalysisSeealso:CORRCOEF,CIRCSHIFT