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

조회 수: 1(최근 30일)
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)

댓글을 달려면 로그인하십시오.

### 답변(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.: https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

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!