Diagonal between two random positions in matrix

20 visualizzazioni (ultimi 30 giorni)
Sebastian Daneli
Sebastian Daneli il 11 Nov 2024 alle 19:37
Risposto: Walter Roberson il 11 Nov 2024 alle 20:03
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 Commento
Torsten
Torsten il 11 Nov 2024 alle 19:40
What do you expect as output if the matrix is 3x3 and the positions are (1,1) and (2,3) ?

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 11 Nov 2024 alle 20:03
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.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by