how can i extrapolate the last value of a matrix?
11 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Jos (10584)
on 14 Feb 2013
Edited: Jos (10584)
on 14 Feb 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 Comments
More Answers (1)
Image Analyst
on 14 Feb 2013
Edited: Image Analyst
on 14 Feb 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 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!