Finding slope from a 2D plot

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 日

5 投票

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 日
If I use the polyfit command it should be on the linear region of the curve right? how can I specify the points.I'am attaching the data points please suggest me with an idea. values in TPM.mat on the Y axis and values in CMOD.mat in X axis. I created a plot. In the plot editor window I inserted a line. How can I find the slop on the increasing part of the curve at the start?
Image Analyst
Image Analyst 2014 年 12 月 7 日
Yes. But I don't know how you plan on finding linear portions. It looks like there could be several chunks of the curve that are roughly linear. There must be some idea in your head about which one you'd pick and what characteristics it has that make you pick that one over all the other possible linear chunks. But personally, I have no idea.
adrooney
adrooney 2014 年 12 月 7 日
The best linear portion I can see is the plot starting from the origin until the first bend of the curve.In the picture, how about the slope of the red line? How can I accomplish the task? I need to join later the green and the red lines and know the point of intersection. But for the start the slopes will help in constructing the line equations. Please help me with this.
In the
Image Analyst
Image Analyst 2014 年 12 月 7 日
Why don't you go from element 1 to N and then plot the slope as a function of N? You'll see it's fairly constant until a certain number of elements and then the slope will head down to zero. I bet if you examine the curve you can come up with some kind of algorithm to pick the best N.
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');

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDiscrete Data Plots についてさらに検索

質問済み:

2014 年 12 月 7 日

コメント済み:

2014 年 12 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by