Code covered by the BSD License

Acoustic Tracker (Updated)

MathWorks Data Acquisition Toolbox Team (view profile)

06 Mar 2003 (Updated )

Demonstrate using the Data Acquisition Toolbox to build an application.

decaycurvefit(x,y1,y2)
```function decaycurvefit(x,y1,y2)
%DECAYCURVEFIT    Create plot of datasets and fits
%   DECAYCURVEFIT(X,Y1,Y2)
%   Creates a plot, similar to the plot in the main curve fitting
%   window, using the data that you provide as input.  You can
%   apply this function to 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.
%
%   Number of datasets:  2
%   Number of fits:  2

% Copyright 1998 - 2001 The MathWorks, Inc

% Data from dataset "Left Mic":
%    X = x:
%    Y = y1:
%    Unweighted

% Data from dataset "Right Mic":
%    X = x:
%    Y = y2:
%    Unweighted
%
% This function was automatically generated

% Set up figure to receive datasets and fits
f_ = clf;
figure(f_);
legh_ = []; legt_ = {};   % handles and text for legend
xlim_ = [Inf -Inf];       % limits of x axis
ax_ = subplot(1,1,1);
set(ax_,'Box','on');
axes(ax_); hold on;

% --- Plot data originally in dataset "Left Mic"
x = x(:);
y1 = y1(:);
h_ = line(x,y1,'Parent',ax_,'Color',[0.333333 0 0.666667],...
'LineStyle','none', 'LineWidth',1,...
'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(x));
xlim_(2) = max(xlim_(2),max(x));
legh_(end+1) = h_;
legt_{end+1} = 'Left Mic';

% --- Plot data originally in dataset "Right Mic"
y2 = y2(:);
h_ = line(x,y2,'Parent',ax_,'Color',[0.333333 0.666667 0],...
'LineStyle','none', 'LineWidth',1,...
'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(x));
xlim_(2) = max(xlim_(2),max(x));
legh_(end+1) = h_;
legt_{end+1} = 'Right Mic';

% --- Create fit "1/r Decay"
st_ = [0.9501292851472 0.2311385135743 ];
ft_ = fittype('rat01' );

% Fit this model using new data
cf_ = fit(x,y2,ft_ ,'Startpoint',st_);

% Or use coefficients from the original fit:
if 0
cv_ = {0.004566294359658, 0.121198959794};
cf_ = cfit(ft_,cv_{:});
end

h_ = plot(cf_,'fit',0.95);
legend off;  % turn off legend from plot method call
set(h_(1),'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_(1);
legt_{end+1} = '1/r Decay';

% --- Create fit "1/r Decay Left"
st_ = [0.9501292851472 0.2311385135743 ];
ft_ = fittype('rat01' );

% Fit this model using new data
cf_ = fit(x,y1,ft_ ,'Startpoint',st_);

% Or use coefficients from the original fit:
if 0
cv_ = {0.006838021722671, 0.2221929378311};
cf_ = cfit(ft_,cv_{:});
end

h_ = plot(cf_,'fit',0.95);
legend off;  % turn off legend from plot method call
set(h_(1),'Color',[0 0 1],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_(1);
legt_{end+1} = '1/r Decay Left';

hold off;
legend(ax_,legh_, legt_);
```