xcorr (for autocorrelation) with NaN values
问题 I'd like to autocorrelate some data but it has some missing values, is there a quick way to do this in matlab? xcorr returns an array of NaN if any of the input is NaN. e.g. data = [1 2 3 4 NaN 2 3 4 1 2 3 4]; xc = xcorr(data, 'biased'); 回答1: With some insight from Nzbuu, the following works: data = [1 2 3 4 NaN 2 3 4 5]; scaled = (data - nanmean(data)) / nanstd(data); scaled(isnan(data)) = 0; corr = xcorr(scaled); It is necessary to insert zeros after scaling the data, not before, as