Data likes this
-----
3
NaN
NaN
7
NaN
NaN
2
NaN
NaN
19
NaN
NaN
12
-----
How interpolate NaN data?
I try interp1 fuction. But I failed.
Please help me.

1 comentario

Jan
Jan el 14 de Nov. de 2016
Whenever you post "failed" in the forum, add your code and explain the error.

Iniciar sesión para comentar.

 Respuesta aceptada

John D'Errico
John D'Errico el 14 de Nov. de 2016
Editada: John D'Errico el 14 de Nov. de 2016

0 votos

Download inpaint_nans from the File Exchange. Although interp1 would also have been able to solve the problem too. inpaint_nans is far simpler to use for this though.

4 comentarios

Jeong_evolution
Jeong_evolution el 14 de Nov. de 2016
Could you make a function used interp1? I feel difficult inpaint_nans. sorry
John D'Errico
John D'Errico el 14 de Nov. de 2016
Editada: John D'Errico el 14 de Nov. de 2016
Why is one line of code difficult, with NO extra arguments needed?
x = [3
NaN
NaN
7
NaN
NaN
2
NaN
NaN
19
NaN
NaN
12];
y = inpaint_nans(x)
y =
3
5.4342
7.0427
7
4.4804
1.9813
2
7.0339
13.796
19
19.359
16.487
12
Are you seriously trying to tell me that is difficult to use?
John D'Errico
John D'Errico el 14 de Nov. de 2016
This is easier?
k = find(~isnan(x));
y = interp1(x(k),y(k),1:numel(x));
It is not difficult. But you cannot claim it to be simpler to use interp1 here.
Jeong_evolution
Jeong_evolution el 18 de Nov. de 2016
I'm sorry. I didn't work hard.
Very easy.. Thanks ^^

Iniciar sesión para comentar.

Más respuestas (1)

Jan
Jan el 14 de Nov. de 2016
data = [3, NaN, NaN, 7, NaN, NaN, 2, NaN, NaN, 19, NaN, NaN, 12];
miss = isnan(data);
data(miss) = interp1(data(~miss), find(~miss), find(miss))

4 comentarios

Jeong_evolution
Jeong_evolution el 14 de Nov. de 2016
Thanks Jan Simon. Your answer is very inormative for me. But, I have a question. What is express "~miss"? I'm sorry.
Jan
Jan el 14 de Nov. de 2016
"~" is the NOT operator. Try this:
data = [3, NaN, NaN, 7, NaN, NaN, 2, NaN, NaN, 19, NaN, NaN, 12];
miss = isnan(data);
disp(miss)
disp(~miss)
Jeong_evolution
Jeong_evolution el 18 de Nov. de 2016
Mr.Simon. This is real data.
When I try this code used real data, there was an error.
But I don't know mean. You know?
Jeong_evolution
Jeong_evolution el 18 de Nov. de 2016
Code is
------------------------------------------------------------------------------------
AA = xlsread('TMY_original_mssing_2');
data = AA(:,1:3);
miss = isnan(data);
data(miss) = interp1(data(~miss), find(~miss), find(miss));
------------------------------------------------------------------------------------

Iniciar sesión para comentar.

Categorías

Preguntada:

el 14 de Nov. de 2016

Comentada:

el 18 de Nov. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by