How can I determine the y-intercept from known x and y values?

조회 수: 38 (최근 30일)
Benjamin Horsley
Benjamin Horsley 2021년 4월 18일
댓글: Benjamin Horsley 2021년 4월 19일
I have a series of known x and y values (both 161x1 double) and I would like to plot a line graph and determine the slope and y-intercept of the data. I know there have been a few similar posts, but I'm just a little confused as to the correct method to perform this. I would like to determine the y-intercept as part of a residual analysis for biomechanical data.
Thank you.

채택된 답변

Robert Brown
Robert Brown 2021년 4월 18일
편집: Robert Brown 2021년 4월 18일
define a vector, x
x = 1:10
define a slope, m
define an intercept, b
NOTE: I did this for the example, to generate the data, you of course would skip this step
m = 2
b = 17
compute y = m*x + b
NOTE: I did this for the example, to generate the data, you of course would skip this step
y = m * x + b
make a plot of the data, plotting variable x along the x axis, and variable y along the y axis
figure
plot(x,y)
xlabel('x values')
ylabel('y values')
title('plot of x,y values')
solve for slope by the following equation, when expression is order = 1 (no x-squared or x-cubed terms...etc)
slope = (y(end) - y(1)) / (x(end) - x(1))
solve for intercept by computing y - m* x = b
intercept is computed for each of my 10 points (or your 161 points), and is always 17in this example... (or whatever your intercept turns out to be)... as it should be
intercept = y - slope*x
I hope this helps !

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Biological and Health Sciences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by