Interpolate line data to grid matlab
Show older comments
How can I find the points (red circles) which an arbitrary line (blue line) intersects in a grid?

Answers (1)
Star Strider
on 3 Apr 2024
Edited: Star Strider
on 3 Apr 2024
x = [0.0 5.0];
y = [1.0 3.8];
figure
plot(x, y)
grid
hold on
Ax = gca;
xtix = Ax.XTick % X-Tick Grid Line Locations
yvals = interp1(x, y, xtix) % Interpolate
scatter(xtix, yvals) % Plot Results
hold off
ylim([0 5])
Also, if you do not have the information that created the plot, you can get it from the plot —
GetLines = findobj(Ax, 'Type','Line');
xv = GetLines.XData
yv = GetLines.YData
yvals = interp1(xv, yv, xtix)
EDIT — (3 Apr 2024 at 21:47)
Added the last part with ‘GetLines’ and following code.
.
Categories
Find more on Lighting, Transparency, and Shading 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!