how can I interpolate NaN values and correlate a matrix

2 ビュー (過去 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 Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by