how can i extrapolate the last value of a matrix?

Dear all,
I have this matrix
clear all
A={
'02/2000' [NaN] [NaN]
'03/2000' [NaN] [3]
'04/2000' [NaN] [5]
'05/2000' [4] [4]
'06/2000' [3.9313] [0.9313]
'07/2000' [3.9313] [3.9313]
'08/2000' [NaN]} [45]}
'09/2000' [4.1583] [44.1583]
'10/2000' [3.9389] [334.9389]
'11/2000' [4.3944] [45.3944]
'12/2000' [4] [4.56]
'01/2001' [3.9313] [56.9313]
'02/2001' [3.743] [4.9543]
'03/2001' [NaN] [NaN]}
my goal is to extrapolate the values of the last observations, that is, the observations that corresponds to the
the date '03/2001'
Is there a way to do that in matlab?
Note that I have many such vectors and the last date for each vector is different.
Cheers

 Réponse acceptée

Jos (10584)
Jos (10584) le 14 Fév 2013
Modifié(e) : Jos (10584) le 14 Fév 2013
You have to define a model first. As an example, assume you have data points (time, value) like this:
Time = [1 3 6 7 8]
Value = [10 11 15 19 25]
and you want to get the value at an unknown time. You could, for instance, fit a linear model "Value = a x Time +b" through the known data points by which you get the parameters a and b, and in turn retrieve the predicted values at unknown times.
p = polyfit(Time,Values,1)
Value10 = polyval(p,10)
However, there are many, many issues to be aware of! For instance, what is the underlying model? Linear or not? Also, extrapolation is often very tricky ...

4 commentaires

tzaloupas
tzaloupas le 14 Fév 2013
Modifié(e) : Image Analyst le 14 Fév 2013
thanks Jos. I am interested in both polyfit() and extrapolation.
Could you please be a bit more specific about the code that I have to use in my question?
thanks
José-Luis
José-Luis le 14 Fév 2013
You have not answered Jos question. What sort of data is this? What sort of model are you using? To blindly extrapolate is a bad habit. Extrapolation is dangerous and can have disastrous consequences (the crash of the Challenger, e.g.)
tzaloupas
tzaloupas le 14 Fév 2013
thanks Jose . My data are on prices of goods. I tried to extrapolate the last observation and in some cases I obtain negative prices
I do not have a specific model in my mind. Is there anything you can do to help me with the above example?
thanks
José-Luis
José-Luis le 14 Fév 2013
Modifié(e) : José-Luis le 14 Fév 2013
I am sorry, but if I had a reliable model to extrapolate the price of goods I would be a very very very very rich man. What you are asking is not simple, to say the least.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 14 Fév 2013
Modifié(e) : Image Analyst le 14 Fév 2013
If you want to fit, say, 123 locations between -2 and 42 you could create your x data:
xFitted = linspace(-2, 42, 123);
Now get the fit:
monthNumber = % Extract this from column 1
column2 = % Extract this from column 2.
coefficients = polyfit(monthNumber , column2 , 1); % Or whatever order of polynomial you want.
Then do the fit/extrapolation:
yFitted = polyval(coefficients, xFitted);
yFitted will be the fitted y values between -2 and 42. Since your data went from month 2 to month 15, values from -2 to 2 and from 15 to 42 are extrapolated. Values between 2 and 15 are fitted/interpolated/regressed because they occur within the valid training range of your data.

3 commentaires

tzaloupas
tzaloupas le 14 Fév 2013
thanks Image analyst. Still can not understand how to apply your appraoch to my example. could you help me a bit more?
thanks
tzaloupas
tzaloupas le 14 Fév 2013
please? I am struggling to find the answer and I cant
tzaloupas
tzaloupas le 14 Fév 2013
anybody else?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by