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 diameterylabel timegrid onhold on;axis([0 22 0 41]);
Produced graph through my code:
How I want it to look:
%
Best Answer