Plotting of trend in subplots of scatter plot.

조회 수: 7 (최근 30일)
Sujata Dhar
Sujata Dhar 2022년 9월 2일
답변: Star Strider 2022년 9월 2일
I want to plot linear trend in each of the subplots. Please inform me on how to do it.
x=[ 1 2 3 4 5 6 7 8 9 10];
y1 =[ 10 20 30 45 57 78 80 90 100];
y2=[11 22 33 44 55 66 77 88 99 110];
y3 =[23 20 34 35 36 37 38 44 55 99];
subplot(3,1,1);
scatter(x,y1);
subplot(3,1,2);
scatter(x,y2);
subplot(3,1,3);
scatter(x,y3)
Thank you very much
  댓글 수: 3
Sujata Dhar
Sujata Dhar 2022년 9월 2일
There is nothing wrong in the code. I want to add function for plotting linear trend in each subplot or each scatter plots. I don't know that.

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

채택된 답변

Star Strider
Star Strider 2022년 9월 2일
Use the lsline function —
x=[ 1 2 3 4 5 6 7 8 9 10];
y1 =[ 10 20 30 45 57 78 80 90 100];
y2=[11 22 33 44 55 66 77 88 99 110];
y3 =[23 20 34 35 36 37 38 44 55 99];
subplot(3,1,1);
scatter(x(1:numel(y1)),y1);
h1 = lsline;
subplot(3,1,2);
scatter(x,y2);
h2 = lsline;
subplot(3,1,3);
scatter(x,y3)
h3 = lsline;
I return the handles to the lsline calls in the event you want to calculate their parameters. The easiest way to do that would be:
h1p = polyfit(h1.XData, h1.YData, 1);
and so for the others. The first element of ‘h1p’ is the slope and the second the intercept.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by