How to ask MATLAB to predict the next value in a graph

13 views (last 30 days)
I have a linear graph with the cost of advertising on a platform over time, versus the date. I am looking to use Matlab to estimate the next point on the graph.
I have looked at YPred, but I am unsure about how to format my data so that it understands what it needs to make the prediction. I am also unclear as to what type of model I would be specifying.
ypred = predict(mdl,DATASET)
is what I am using, but it doesn't make any sense.
Any suggestions or advice would be appreciated, I have exhausted the MATLAB resources sadly.

Accepted Answer

Image Analyst
Image Analyst on 18 Jan 2019
Use polyfit() and polyval():
coefficients = polyfit(t, cost, 1); % Do a linear fit
predictedCost = polyval(coefficients, t); % Get value of linear fit at time t.
  1 Comment
Helena Leathers
Helena Leathers on 22 Jan 2019
Thank you! This worked, but it returned a whole bunch of data that is linear. The data it returned started from the lowest point of my original graph and stepped up to the highest.
How could I ask MatLab to recalculate the next value in addition to the previous one it found? Applicability wise, the first data point is interesting but a linear pattern isn't like reality. Is there a way to get the program to consider this?
Thanks again, I spent hours trying to figure this out on my own. I am eternally grateful!

Sign in to comment.

More Answers (1)

Cris LaPierre
Cris LaPierre on 18 Jan 2019
You probably want to extrapolate. See this answer.
You could also consider fitting the data using polyfit, then calculating the y value for a given x value using polyval. The this example in the documentation.

Categories

Find more on Descriptive Statistics 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!