Borrar filtros
Borrar filtros

how can i extrapolate the last value of a matrix?

8 visualizaciones (últimos 30 días)
tzaloupas
tzaloupas el 14 de Feb. de 2013
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

Respuesta aceptada

Jos (10584)
Jos (10584) el 14 de Feb. de 2013
Editada: Jos (10584) el 14 de Feb. de 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 comentarios
tzaloupas
tzaloupas el 14 de Feb. de 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 el 14 de Feb. de 2013
Editada: José-Luis el 14 de Feb. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Feb. de 2013
Editada: Image Analyst el 14 de Feb. de 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 comentarios
tzaloupas
tzaloupas el 14 de Feb. de 2013
please? I am struggling to find the answer and I cant
tzaloupas
tzaloupas el 14 de Feb. de 2013
anybody else?

Iniciar sesión para comentar.

Categorías

Más información sobre Price and Analyze Financial Instruments en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by