MATLAB Examples

book_3_25.m

Use labels instead of legend.

load dating

x = CarbonAge;
y = ThoriumAge-CarbonAge;
n = 1;  %  first degree fit for straight line
sortx = sort(x);
% Plot the line through most of the data
newx = linspace(sortx(1),0.6*(sortx(end)+sortx(end-1)),50);

% bisquare fit
p = least2b(x,y,n);
newy = polyval(p,newx);

% unweighted fit
p = polyfit(x,y,n);
unwy = polyval(p,newx);

% Plot the data and both fit lines.
hg = plot(x,y,'.',newx,newy,'-',newx,unwy,'m--');
set(hg(1), 'MarkerSize',24)
set(hg(2), 'LineWidth',2)
set(hg(3), 'LineWidth',2)
xlabel('Carbon Age, 1000 years')
ylabel('Thorium Age - Carbon Age, 1000 years')
title('Nuclear Dating Comparison')
text(8,3,'Robust fit \rightarrow')
text(17, 2.8,'\leftarrow Standard fit')

naxis = axis;
naxis(4) = ceil(max(y)+0.5);
axis(naxis)