MATLAB Answers

how to get the position of a line in from a 2D matrix data.

1 ビュー (過去 30 日間)
Abhijeet Kumar
Abhijeet Kumar 2021 年 7 月 30 日
回答済み: Walter Roberson 2021 年 7 月 30 日
can anyone help me to get the data from a 2D matrix along any crosssection (after drawing a line).
I need to extract such datapoints from a 2D matrix which will direclty underly the straight line as shown in figure.
Actually I need the intersection position or location of a line in 2D grid.
data size: x = (164,164); y = (164,164); data = (164,164)
Thanks in Advance.

回答 (2 件)

KSSV 2021 年 7 月 30 日
If you have grid data X, Y,Z and you want to get the values at the points (x,y), you can use interp2.
zi = interp2(X,Y,Z,x,y) ;
To calculate the intersection points consider using InterX from file exchange.:

Walter Roberson
Walter Roberson 2021 年 7 月 30 日
Note that you pass in endpoints of line segments, and it automatically decides the exact list of points to sample along.
If you want more control over exactly where it is sampled, then instead of using improfile(), use interp2(), supplying vectors for the x and y query points -- and be careful about x and y versus row and columns (x == columns, y == rows). When your x and y query vectors are the same size and same orientation, then the values will be interpolated at those points only (if they have different orientations then the query would be over a grid if I recall correctly.)

Community Treasure Hunt

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

Start Hunting!

Translated by