Matlab help(distance of several points from a line)

In summary, the conversation discusses calculating the minimum distance of a set of points from a given line using a specific equation. The issue is determining which point corresponds to the minimum distance.
  • #1
supernova1387
31
0
Hi

I have a matrix a like below:

a=[1:19;2:20];

The minimum distance of these points from the line y=x can be calculated like this:
d=abs(-a(:,1)+a(:,2))/sqrt(2);
min(d)

using the equation of the distance of a point from a line:

d=abs(ax0+by0+c)/sqrt(a^2+b^2)

Now my problem is this:
I can find the distance of all the points from the line y=x easily and I can find the min distance but I don't know which point does this minimum distance refers to? I don't think this is difficult but I don't know the command. Something which after calculating the min distance tells me what is that point from matrix a

Thanks in advance
 
Physics news on Phys.org
  • #2
So let me get this straight. You need the position of min(d) inside of the vector d?
 

1. How can I calculate the distance of several points from a line using Matlab?

To calculate the distance of several points from a line using Matlab, you can use the point2line function. This function takes the coordinates of the points and the equation of the line as inputs and returns the distance of each point from the line as output.

2. Can I plot the distance of several points from a line using Matlab?

Yes, you can plot the distance of several points from a line using the plot function in Matlab. First, use the point2line function to calculate the distances and store them in a variable. Then, use the plot function to plot the distances against the points.

3. How can I find the equation of a line that passes through a set of points in Matlab?

To find the equation of a line that passes through a set of points in Matlab, you can use the polyfit function. This function takes the coordinates of the points as inputs and returns the coefficients of the equation of the line as output.

4. Is there a built-in function in Matlab for calculating the distance of a point from a line?

Yes, there is a built-in function in Matlab called dist that can be used to calculate the distance of a point from a line. This function takes the coordinates of the point and the equation of the line as inputs and returns the distance as output.

5. Can I calculate the perpendicular distance of a point from a line using Matlab?

Yes, you can calculate the perpendicular distance of a point from a line using the perpdist function in Matlab. This function takes the coordinates of the point and the equation of the line as inputs and returns the perpendicular distance as output.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
827
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
862
Back
Top