Hi, I have a matrix with 160 numbers, but the first values is nan. How I complete this matrix? Anyone help me? I try the -- interp1 --- but I have only a matrix, I do not have a vector to realize the extrapolation.
Thank you for your attention. Best wishes, Paulo Oliveira

2 commentaires

José-Luis
José-Luis le 15 Mai 2014
Extrapolation is tricky business. Depending on the sort of data different extrapolation methods might be warranted. The closest value? A linear interpolation from the first two points. A cuadratic function using the last three points? A spline of n degree?
Extrapolation caused the crash of the Challenger.
Paulo Oliveira
Paulo Oliveira le 15 Mai 2014
I understand your questions, but as I said, I have 160 values, but 40 are NAN, so I have a 140 values to support,for you what the best way to do the data extrapolation?

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 15 Mai 2014

3 votes

This works:
% Original vector:
x = 1:10
% Replace the first 4 elements with ‘NaN’:
x(1:4) = NaN
% Create empty elements for the ‘NaN’ elements:
x(isnan(x)) = []
% Extrapolate to fill the empty elements:
xm = interp1(x, -3:0, 'linear', 'extrap')
produces:
xm =
1. 2 3 4

4 commentaires

Paulo Oliveira
Paulo Oliveira le 15 Mai 2014
Hi Star Strider,
I try with my matrix and works like I want. :)
Thank you for your attention.
Best wishes, Paulo Oliveira
Star Strider
Star Strider le 15 Mai 2014
My pleasure!
Anwaar Alghamdi
Anwaar Alghamdi le 24 Nov 2022
Modifié(e) : Anwaar Alghamdi le 24 Nov 2022
@Star Strider Does this work if I have missing hourly temperature values? (not NaN but 999)
One or two missing values is fine but if a have a whole day missing? Can this preserve the behavior of hourly temprature profile within the day?
Star Strider
Star Strider le 29 Avr 2023
@Anwaar Alghamdi — I just now saw this.
It depends on what the data are and where the values are that are NaN. The fillmissing function would likely be most appropriate.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by