how can I interpolate NaN values and correlate a matrix

조회 수: 4 (최근 30일)
juan
juan 2012년 8월 17일
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개)

Oleg Komarov
Oleg Komarov 2012년 8월 17일
[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
Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 17일
he needs statsitcs toolbox for "corr"
Oleg Komarov
Oleg Komarov 2012년 8월 17일
편집: Oleg Komarov 2012년 8월 18일
Yes, forgot that.
@Juan: in addition, you can simply use 'pairwise' option of corr() to avoid NaNs.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by