function [k,a] = powerfit(xdata,ydata)
% Power law fit for model y = k*x^a
% Uses linear least squares fit to logarithms of data
Y = log(ydata);      % Logarithm of y-data
X = log(xdata);      % Logarithm of x-data
p = polyfit(X,Y,1);  % Linear fit to X and Y
a = p(1);            % Value of exponent
k = exp(p(2));       % Value of leading coefficient
end
