creatGolf_Fit.m

Back to Home

function createGolf_Fit(mat_time,mat_x,mat_y,mat_z,mat_HIT)
%CREATEFIT Create plot of data sets and fits
%   CREATEFIT(MAT_TIME,MAT_X,MAT_Y,MAT_Z,MAT_HIT)
%   Creates a plot, similar to the plot in the main Curve Fitting Tool,
%   using the data that you provide as input.  You can
%   use this function with the same data you used with CFTOOL
%   or with different data.  You may want to edit the function to
%   customize the code and this help message.
%


% Auto-generated by MATLAB on 30-Apr-2011 15:57:43

% Set up figure to receive data sets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[658 269 688 485]);
% Line handles and text for the legend.
legh_ = [];
legt_ = {};
% Limits of the x-axis.
xlim_ = [Inf -Inf];
% Axes for the plot.
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',[0 0 1 1]);
set(ax_,'Box','on');
axes(ax_);
hold on;

% --- Plot data that was originally in data set "mat_x vs. mat_time"
mat_time = mat_time(:);
mat_x = mat_x(:);

% --- Plot data that was originally in data set "mat_y vs. mat_time"
mat_y = mat_y(:);

% --- Plot data that was originally in data set "mat_z vs. mat_time"
mat_z = mat_z(:);

% --- Plot data that was originally in data set "mat_HIT vs. mat_time"
mat_HIT = mat_HIT(:);

%Commented Section
x_ax_max = max(mat_time);
set(ax_, 'XLim', [0, x_ax_max]);
% Nudge axis limits beyond data limits
% if all(isfinite(xlim_))
%     xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
%     set(ax_,'XLim',xlim_)
% else

%   set(ax_, 'XLim',[-64.070000000000007, 6573.0699999999997]);
% end


% --- Create fit "X_Axis"
ok_ = isfinite(mat_time) & isfinite(mat_x);
if ~all( ok_ )
    warning( 'GenerateMFile:IgnoringNansAndInfs',...
        'Ignoring NaNs and Infs in data.' );
end
ft_ = fittype('smoothingspline');

% Fit this model using new data
cf_ = fit(mat_time(ok_),mat_x(ok_),ft_);

% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',[1 0 0],...
    'LineStyle','-', 'LineWidth',2,...
    'Marker','none', 'MarkerSize',6);
% Turn off legend created by plot method.
legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'X_Axis';

% --- Create fit "Y_Axis"
ok_ = isfinite(mat_time) & isfinite(mat_y);
if ~all( ok_ )
    warning( 'GenerateMFile:IgnoringNansAndInfs',...
        'Ignoring NaNs and Infs in data.' );
end
ft_ = fittype('smoothingspline');

% Fit this model using new data
cf_ = fit(mat_time(ok_),mat_y(ok_),ft_);

% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',[0 0 1],...
    'LineStyle','-', 'LineWidth',2,...
    'Marker','none', 'MarkerSize',6);
% Turn off legend created by plot method.
legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'Y_Axis';

% --- Create fit "Z_Axis"
ok_ = isfinite(mat_time) & isfinite(mat_z);
if ~all( ok_ )
    warning( 'GenerateMFile:IgnoringNansAndInfs',...
        'Ignoring NaNs and Infs in data.' );
end
ft_ = fittype('smoothingspline');

% Fit this model using new data
cf_ = fit(mat_time(ok_),mat_z(ok_),ft_);

% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',[0.666667 0.333333 0],...
    'LineStyle','-', 'LineWidth',2,...
    'Marker','none', 'MarkerSize',6);
% Turn off legend created by plot method.
legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'Z_Axis';

% --- Create fit "HIT"
ok_ = isfinite(mat_time) & isfinite(mat_HIT);
if ~all( ok_ )
    warning( 'GenerateMFile:IgnoringNansAndInfs',...
        'Ignoring NaNs and Infs in data.' );
end
ft_ = fittype('smoothingspline');

% Fit this model using new data
cf_ = fit(mat_time(ok_),mat_HIT(ok_),ft_);

% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',[0.333333 0.333333 0.333333],...
    'LineStyle','-', 'LineWidth',2,...
    'Marker','none', 'MarkerSize',6);
% Turn off legend created by plot method.
legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'HIT';

% --- Finished fitting and plotting data. Clean up.
hold off;
% Display legend
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:});
set(h_,'Interpreter','none');
% Remove labels from x- and y-axes.
xlabel(ax_,'Time <ms>');
ylabel(ax_,'Relative G-Force');

% Title
title ('Plot of Relative G-Force versus Time');