MATLAB: How to extend curve fit beyond data points

curve fitting

I have plotted my data and fitted a curve onto it. However, I am not able to extend my fit beyond my data points (I want it to go through my points and through the axis).
My code:
function [fitresult, gof] = createFit(diameter, time)
%%Fit: 'Raw Data'.
[xData, yData] = prepareCurveData( diameter, time );
% Set up fittype and options.
ft = fittype( 'power1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [155.522818446907 -1.88432816467686];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data
figure( 'Name', 'Raw Data' );
h = plot( fitresult,'b', xData, yData, '.k' );
h(1).MarkerSize = 12;
h(2).LineWidth = 1;
legend( h, 'time vs. diameter', 'Raw Data', 'Location', 'NorthEast' );
% Label axes
xlabel diameter
ylabel time
grid on
hold on;
axis([0 22 0 41]);
Produced graph through my code:
How I want it to look:
%

Best Answer

You have the coefficients of the 'power1' function stored in fitresult. It probably looks something like this:
fitresult =
General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 1.46 (1.22, 1.69)
b = 0.40 (0.38, 0.43)
with 1.46 and 0.40 being the coefficients. Just create new bounds by
x=linspace(xmin,xmax,n)
and plug it into the equation
y=(fitresult.a).*x.^(fitresult.b)
plot(x,y)
Related Question