How to plot Multiple trend-lines on one scatter plot
이전 댓글 표시
Hi every one,
I have a scatter plot and I need to do a second order trend line for some part of my data (just for the values less than 15 or 10 on x axis). Do you know how can I do that?

답변 (1개)
You can pick those respective points and fit a curve to plot the trend. Let x,y be your points.
x1 = x(x<=15) ; % pick points less than 15
y1 = y(x<=15) ;
p1 = polyfit(x1,y1,1) ; % Fit a line
figure
hold on
plot(x,y,'.k')
plot(x1,polyval(p1,x1),'r')
댓글 수: 11
Same thin, pick those points and fit a curve again.
x2 = x(x>15) ;
y2 = y(x>15) ;
p2 = polyfit(x2,y2,1) ;
Note: I have edited the answer, there were few typo errors.
Nicky T
2020년 9월 13일
KSSV
2020년 9월 14일
You have to take continuous x-data to join them. In here you have taken different values. Show the code which you tried.
Image Analyst
2020년 9월 14일
I think you meant 2 in polyfit(), and p1 in polyval().
p1 = polyfit(x1,y1,2) ; % Fit a second order polynomial
figure
hold on
plot(x,y,'.k')
plot(x1,polyval(p1,x1),'r') % p1, not p
KSSV
2020년 9월 14일
@Image Analyst..yes..corrected it.
Image Analyst
2020년 9월 14일
Nicky, please draw what you want in red over your scatterplot. And since you seem to have three separate trends (2 flat and one curved), why do you want their endpoints connected?
Nicky T
2020년 9월 14일
KSSV
2020년 9월 14일
What are values of tRet, tSupp ??
Nicky T
2020년 9월 14일
카테고리
도움말 센터 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
