필터 지우기
필터 지우기

how can i extrapolate the last value of a matrix?

조회 수: 8 (최근 30일)
tzaloupas
tzaloupas 2013년 2월 14일
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

채택된 답변

Jos (10584)
Jos (10584) 2013년 2월 14일
편집: Jos (10584) 2013년 2월 14일
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
tzaloupas
tzaloupas 2013년 2월 14일
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 2013년 2월 14일
편집: José-Luis 2013년 2월 14일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 2월 14일
편집: Image Analyst 2013년 2월 14일
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
tzaloupas
tzaloupas 2013년 2월 14일
please? I am struggling to find the answer and I cant
tzaloupas
tzaloupas 2013년 2월 14일
anybody else?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Price and Analyze Financial Instruments에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by