Finding intersection of curve and a line
4 views (last 30 days)
Show older comments
Hello! I apologize if that has been asked before - I tried finding an answer but I didn't really understand any of them/many of them didn't work because it wasn't for this situation specifically.
I have this graph (see below), with two y lines on them. I was hoping to find the coordinate intersection of the bottom line (let's call it secondY) and the exponential curve (which we can call curve). I would then like to draw an x line wherever the intersection x value is. What would be the simplest way to do this?
I appreciate your help, thank you!
0 Comments
Answers (1)
Star Strider
on 1 Jul 2019
Your ‘curve’ has noise between x=0 and x=200 or so. You will likely need to exclude that region.
One option is to use interp1, for example:
xq = interp1(curve(idxrng), x(idxrng), lineval);
where ‘idxrng’ are the index values that exclude the noise, and ‘lineval’ is whatever y-value the line has.
Another option is to use polyfit to approximate the exponentially-descending part of the curve:
p = polyfit(x(idxrng), y(idxrng), 3);
xq = roots(p - lineval);
Without your data, it is not possible to write specific code.
0 Comments
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!