Interpolate line data to grid matlab

2 ビュー (過去 30 日間)
Reza Zh
Reza Zh 2024 年 4 月 3 日
編集済み: Star Strider 2024 年 4 月 3 日
How can I find the points (red circles) which an arbitrary line (blue line) intersects in a grid?

回答 (1 件)

Star Strider
Star Strider 2024 年 4 月 3 日
編集済み: Star Strider 2024 年 4 月 3 日
Use the interp1 function —
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
xtix = 1x6
0 1 2 3 4 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
yvals = interp1(x, y, xtix) % Interpolate
yvals = 1x6
1.0000 1.5600 2.1200 2.6800 3.2400 3.8000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
xv = 1x2
0 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
yv = GetLines.YData
yv = 1x2
1.0000 3.8000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
yvals = interp1(xv, yv, xtix)
yvals = 1x6
1.0000 1.5600 2.1200 2.6800 3.2400 3.8000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
EDIT — (3 Apr 2024 at 21:47)
Added the last part with ‘GetLines’ and following code.
.

カテゴリ

Help Center および File ExchangeFormatting and Annotation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by