How can I plot a linear regression line on a loglog scatter plot in MATLAB?
Ältere Kommentare anzeigen
I have a dataset of 168rows & 2colmns, plot them with a loglog scale.Now I have to plot the regression line on it,I have no special matlab tools to use "lsline" or ...
How can we draw the regression line on a loglog plot?
I find some rows of code and tried them but didn't work.
Any help will be appreciated.
clear
clc
numdata = xlsread('Hayes2017_datasheet.xlsx');
moment = numdata(:,6);
average_slip = numdata(:,13);
% M0=log10(moment);
% av_slip=log10(average_slip);
%
% xd=M0(:)-mean(M0);
% yd=av_slip(:)-mean(av_slip);
%
% squre_xd=xd.^2;
% squre_yd=yd.^2;
%
% xy_d=xd.*yd;
%
% Sxy=sum(xy_d);
% Sxx=sum(squre_xd);
% a=Sxy./Sxx;
% ave_point=[mean(M0);mean(av_slip)];
% b=ave_point(2)-(a*ave_point(1))
% y_hat=(b*(M0.^a))
loglog(moment,average_slip,'o')
% hold on
% % lsline
% plot(moment,y_hat)
X = [ones(length(moment),1) moment];
b = X\average_slip;
yCalc2=b(1)+moment*b(2)
loglog(moment,yCalc2,'--')
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Exploration and Visualization finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!