MATLAB: Adding log-linear trend to scatterplot

add trendlinelog-linear trendscatterplot

Hi. I am trying to add a log-linear trend to a scatterplot with log y axis, but I cant seem to figure out how to do it. It is a very simple plot like this:
>> scatter(data1,data2)
>> set(gca, 'yScale', 'log')
Any suggestions on how to add a log-linear trend? Thanks in advan[c]e.
IR

Best Answer

Fit the log(y), compute the fitted result and add...
b=polyfit(data1,log(data2),1); % ln y = mx + b
yhat=exp(polyval(data1)); % compute fitted result
hold all % prepare to add the fittted line
hLyhat=plot(data1,yhat); % add to the plot; save handle to make fixups as wanted
Related Question