Missing data values with interpolation
Afficher commentaires plus anciens
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));
Réponse acceptée
Plus de réponses (2)
Steven Lord
le 15 Déc 2018
2 votes
1 commentaire
mostafa mahdi yousef
le 19 Déc 2021
this is the best answer thanks Steven!
like ypu from IRAN!
Andrei Bobrov
le 7 Août 2012
Modifié(e) : Andrei Bobrov
le 8 Août 2012
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');
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!