how can I interpolate NaN values and correlate a matrix

Hi anyone can help me? I have a matrix A(9x8)which corresponds to a time series records that have NaN missing values. I need to do both, first interpolate those NaN values and second cross-correlate every row with all the rest in order to get correlation values that I will use to cluster rows with similar time series behaviour according to the coefficient of correlation. The matrix is something like this:
A= ...
[48.4 34.77 47.77 NaN 42.77 44.85 46.75 47.16
45.27 37.6 48.18 NaN 46 44.38 48.48 49.19
46.35 40.81 45.51 NaN 43.29 43.38 48.29 NaN
45.38 42.25 42.86 NaN 39.62 46.05 NaN 54.28
43.84 36.63 48.13 NaN 39.62 45.37 55.55 48.49
43.36 36.82 47.88 NaN 36.58 46.91 47.05 49.56
44.54 38.38 50.35 NaN 41.98 45.32 NaN 53.45
45.5 37.68 44.2 NaN 42.88 NaN 50.27 50.02
55.50 38.62 43.48 NaN 42.08 46.35 51.53 53.43]
Thank you so much for your help, JC

回答(1 个)

[rr,cc] = size(A);
% Values to interpolate
xi = 1:cc;
% Index the non NaNs
idx = ~isnan(A);
% Loop for each row and linearly interpoalte and extrapolate
for r = 1:rr
A(r,:) = interp1(xi(idx(r,:)),A(r,idx(r,:)),xi,'linear','extrap');
end
corr(A')

2 个评论

he needs statsitcs toolbox for "corr"
Yes, forgot that.
@Juan: in addition, you can simply use 'pairwise' option of corr() to avoid NaNs.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息

提问:

2012-8-17

Community Treasure Hunt

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

Start Hunting!

Translated by