Diagonal between two random positions in matrix

조회 수: 1 (최근 30일)
Sebastian Daneli
Sebastian Daneli 2024년 11월 11일
답변: Walter Roberson 2024년 11월 11일
Hi
I have a Matrix, and two random positions in it. Now I want all the positions of the matrix that is on the line that passes through the two positions. I.e. I have the positions (x1,x2) and (y1,y2) of a Matrix, and I want the positions of the all the elements that is on the line that passes through this position in the matrix.
Thanks in advance.
  댓글 수: 1
Torsten
Torsten 2024년 11월 11일
What do you expect as output if the matrix is 3x3 and the positions are (1,1) and (2,3) ?

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

답변 (1개)

Walter Roberson
Walter Roberson 2024년 11월 11일
Use
[x2, y2, P] = impixel(xref,yref,YourMatrix,xi,yi)
impixel will first determine whether the x distance of the difference is larger than the y distance of the difference. Whichever is larger will be treated as the distance to be incremented over, with linear interpolation happening over the other distance.
You can do the same thing using interp2(), provided that you are smart about the distance you increment over.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by