Missing data values with interpolation
13 ビュー (過去 30 日間)
古いコメントを表示
Emmanuelle
2012 年 8 月 7 日
コメント済み: mostafa mahdi yousef
2021 年 12 月 19 日
Hello everybody,
I have a cell array each containing a sequence of diferent values. The sequences contains some missing values (I've represented with NaN). I would like to replace all this NaN places with numbers. I think the better way is do an interpolation but I don't know how to code this Nan and how to save it on a table in Matlab.
I1= interp1(x,y,'linear');
Greetings,
Pd) I've tried this but it doesn't work
nanData = isnan(y);
index = 1:numel(y);
data2 = y;
data2(nanData) = interp1(index(~nanData), y(~nanData), index(nanData));
0 件のコメント
採用された回答
Azzi Abdelmalek
2012 年 8 月 7 日
編集済み: Azzi Abdelmalek
2012 年 8 月 7 日
x={ 1 2 3 4 5 6 7 8 9 10}
y={ 0.3850 NaN 3.0394 NaN 0.6475 1.0000 1.5000 NaN 1.1506 0.58}
x=cell2mat(x);y=cell2mat(y);
xi=x(find(~isnan(y)));yi=y(find(~isnan(y)))
result=interp1(xi,yi,x,'linear')
4 件のコメント
Mritula C
2018 年 12 月 15 日
Hi, im facing the same issue. Can you explain what do you mean by " see ADD in my answer" ?
その他の回答 (2 件)
Andrei Bobrov
2012 年 8 月 7 日
編集済み: Andrei Bobrov
2012 年 8 月 8 日
eg
data
Data = cell(1,5);
for jj = 1:5
k = [randi(250,randi([10,15]),1); nan(randi([0 3]),1) ];
Data{jj} = k(randperm(numel(k)));
end
solution
for jj = 1:numel(Data)
n = (1:numel(Data{jj}))';
k = ~isnan(Data{jj});
Data{jj} = interp1(n(k),Data{jj}(k),n,'linear','extrap');
end
ADD
load doc1.txt
x = doc1(:,1);
y= doc1(:,2);
t = all(~isnan([x,y]),2);
out = interp1(x(t),y(t),x,'linear','extrap');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!