Hello,
I have a file with a difference in acceleration between 2 conditions, filename is 'ad'. I need to draw a line through 25% and 75% of the max of this data and then find the x-position where this line intercepts the x-axis.
As an illustration, this is what I want to do: http://tinypic.com/r/rab7te/5
Any help is appreciated, thanks.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 1 Okt. 2013

0 Stimmen

Use the line() function. Just figure out the two endpoints, which shouldn't be very hard at all. Use "hold on" before you call line() so that you don't blow away the curve.

5 Kommentare

Dennis
Dennis am 1 Okt. 2013
Sorry, but I don't understand what you mean. Could you please explain further? I have the x and y points at 25 and 75% of the max, how do I proceed?
To draw a line between just those two points, you'd do
line([x25, x75], [y25, y75], 'Color', 'r', 'LineWidth', 3);
If you want to extend it past those points a short distance, then just recall high school algebra and the formula for a line:
slope = (y75-y25)/(x75-x25);
xLeft = 80; % Whatever x value you want.
yLeft = slope * (xLeft - x25) + y25;
xRight = 100; % Whatever x value you want.
yRight = slope * (xRight - x25) + y25;
line([xLeft, xRight], [yLeft, yRight], 'Color', 'r', 'LineWidth', 3);
Dennis
Dennis am 1 Okt. 2013
That seems to do it, thanks a lot!
ErnestoE
ErnestoE am 15 Sep. 2020
Does this works for vertical lines too? i.e. if both values of x is the same?
Yes. Just try it. And there is a new function xline() if you want the line to run all the way across the entire distance in y, instead of just between two points inside the axes.
xline(xLeft, 'Color', 'r', 'LineWidth', 3);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by