MATLAB: How to find linear regression of data as follows

semi-log

a=[5;6;7;8];
b=[3.6616;1.5234;0.1589;0.028];
b(:,1)
semilogy(a,(b(:,1)),'-or');
hold on;
title ('Plot showing measured data','FontSize',14, 'FontWeight','bold')
xlabel('Frequency','FontSize',10, 'FontWeight','bold')
ylabel('Magnitude','FontSize',10, 'FontWeight','bold')
axis([4.5 8.5 .01 10]);
hold on
grid on
%Regression
logb=[log10(3.6616);log10(1.5234);log10(0.1589);log10(.028)]
A = [a,ones(size(logb))]
c = A\b
y = (A*c)
plot(a,y,'o-', a,y,'*-')
legend ('Measured Data','Lin. Regression','Location','EastOutside')

Best Answer

I would make two small changes in your code:
logb = log10(b);
A = [a,ones(size(logb))];
c = A\logb;
y = 10.^(A*c);
That appears to do what you want.