How to add trendline to scatterplot?

조회 수: 1,135 (최근 30일)
Ani Asoyan
Ani Asoyan 2020년 12월 27일
편집: Dima 2024년 3월 17일
hi, I have 2 variables with data, like
x=2 1 4 68 4 5
y=5 4 2 23 21 50
I want to add trendline to the scatter plot. how can I do that?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 27일
Something like this
x = [2 1 4 68 4 5]
y = [5 4 2 23 21 50]
p = polyfit(x, y, 1);
px = [min(x) max(x)];
py = polyval(p, px);
scatter(x, y, 'filled')
hold on
plot(px, py, 'LineWidth', 2);
  댓글 수: 2
Ani Asoyan
Ani Asoyan 2020년 12월 27일
Thank you so much !!
Ameer Hamza
Ameer Hamza 2020년 12월 27일
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Dima
Dima 2024년 3월 17일
편집: Dima 2024년 3월 17일
x = [2 1 4 8 4 5]
y = [5 4 2 53 21 50]
p = polyfit(x, y, 1);
px = [min(x) max(x)];
py = polyval(p, px);
scatter(x, y, 'filled')
lsline
lsline command.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by