hello Karolina
here my suggestion; if you need further help , let me know
yes, it's a first polynomial fit once the y data are in log scale
clear all
clf
load moore.mat %xtime and y are 40x1 double
%data for mooores law
% so log(y) is linear with time (linear)
figure(1);semilogy(xtime,y);
y_log10 = log10(y);
% do some smoothing ?
N = 10;
y_log10_smoothed = myslidingavg(y_log10, N);
figure(2);plot(xtime,y_log10,'b',xtime,y_log10_smoothed,'*-r');
% polynomial fit
% Fit a polynomial p of degree 1 to the (x,y) data:
% + remove first and last points of smoothed data
ind = 2:length(xtime)-1;
xs = xtime(ind);
yls = y_log10_smoothed(ind);
p = polyfit(xs,yls,1);
% Evaluate the fitted polynomial p and plot:
% yls_fit = polyval(p,xtime);
% Y = POLYVAL(P,X) returns the value of a polynomial P evaluated at X. P
% is a vector of length N+1 whose elements are the coefficients of the
% polynomial in descending powers:
%
% Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1)
yls_fit = p(1)*xtime + p(2);
figure(3);plot(xtime,y_log10,'o', xs,yls,'--',xtime,yls_fit,'-')
legend('data','data smoothed','linear fit')
% going back from log to linear scale for y
y_lin = 10.^(yls_fit);
% now use the fit model to predict future value
new_x_data = [2015 2020 2025]; % can be scalar or vector
new_y_data = 10.^(p(1)*new_x_data + p(2)); % can be scalar or vector
figure(4);semilogy(xtime,y,'o',xtime,y_lin,'-',new_x_data,new_y_data,'*');
legend('data','model fit','extrapolation')