Finding slope from a 2D plot

조회 수: 49 (최근 30일)
adrooney
adrooney 2014년 12월 7일
댓글: Image Analyst 2014년 12월 7일
I have plotted a group of points using plot(x,y) command. The plot is non linear. I attached a picture with a line drawn on the linear side of the graph. Give me an idea of how to find the slope.
  댓글 수: 2
Star Strider
Star Strider 2014년 12월 7일
Obvious question: Slope of what ?
Four possibilities:
  1. The slope of the line from about 0 to about 0.5 ...
  2. The slope of the relatively linear descending part of the curve between about 1 and 3.75 ...
  3. The descending part of the loop ...
  4. The ascending part of the loop ...
... or something else?
adrooney
adrooney 2014년 12월 7일
sorry to draw the line. I'm attaching a picture with the line.(it is on the ascending part of the loop). What I have done is created a dummy point in the third quadrant and drew the line. I need to find the slope and intersection. Can I do it in matlab?

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

답변 (1개)

Image Analyst
Image Analyst 2014년 12월 7일
I see 4 lines. Anyway, extract the x and y coordinates that you want to fit a line to, then use polyfit:
coefficients = polyfit(x, y, 1);
% Now get the slope, which is the first coefficient in the array:
slope = coefficients(1);
  댓글 수: 6
adrooney
adrooney 2014년 12월 7일
Ok thanks I'll try doing that. One more doubt can't we plot grid lines on the plot and all the four quadrants?
Image Analyst
Image Analyst 2014년 12월 7일
You can use
grid on;
or you can use line() to draw lines at certain, specific places.
xl = xlim();
yl = ylim();
% Draw quadrant dividing lines
xLine = (x(1)+x(2))/2;
yLine = (y(1)+y(2))/2;
% Draw vertical line
line([xLine, xLine], yl, 'Color', 'r', 'LineWidth', 2);
% Draw horizontal line.
line(xl, [yLine, yLine], 'Color', 'r');

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by