Plotting best fit line

Hi everyone,
This is my coding and the figure below is the result. My data are all in excel file but now I don't know how to plot the fit slope.
Can anyone advice me? Thanks in advanced.
S4=xlsread('02-Feb-all.xlsx','N:N');
CStdev=xlsread('02-Feb-all.xlsx','P:P');
%_______________Read data_______________%
x=S4;
y=CStdev;
%______________________________%
figure%>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FIGURE starts
scatter(x,y);
title('February 2014');
%datetick('x', 'HH');
xlabel('Ampilitude scintillation (S4)');
ylabel('Sigma-code-carrier Divergence (meters)');
hold all
%_______________PRNall_______________%

 Accepted Answer

KSSV
KSSV on 4 Jan 2021
Read about polyfit. If (x,y) are your data points.
p = polyfit(x,y,1) ;
yi = polyval(p,x) ;
scatter(x,y);
hold on
plot(x,yi,'r')

1 Comment

Ann
Ann on 4 Jan 2021
Oh My God! Thank you, man! It works!!!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

Ann
on 4 Jan 2021

Commented:

Ann
on 4 Jan 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!