Matlab help(distance of several points from a line)

To determine which point the minimum distance refers to, you can use the index of the minimum value in the distance vector. This can be done using the min() function with two output arguments: the minimum value and its index. In summary, to find the minimum distance of points from a line y=x and determine which point it refers to, you can use the equation d=abs(ax0+by0+c)/sqrt(a^2+b^2) and the min() function with two output arguments.
  • #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
Code:
[value index] = min(d)
 
  • #3
jhae2.718 said:
Code:
[value index] = min(d)

Great. Thanks
 

Related to Matlab help(distance of several points from a line)

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 in Matlab, you can use the built-in function point2line. This function takes in the coordinates of the points and the equation of the line, and returns the distance of each point from the line.

2. Can I plot the distances of the points from the line in a graph?

Yes, you can plot the distances of the points from the line in a graph using the plot function in Matlab. You can use the coordinates of the points and the calculated distances as the x and y values for the plot.

3. How do I find the equation of the line that the points are being compared to?

To find the equation of the line that the points are being compared to, you can use the polyfit function in Matlab. This function takes in the coordinates of the points and returns the coefficients of the line equation in the form of y = mx + b.

4. Is it possible to calculate the distance of a point from a line without using any built-in functions?

Yes, it is possible to calculate the distance of a point from a line without using any built-in functions in Matlab. You can use the formula for calculating the distance between a point and a line, which involves finding the perpendicular distance from the point to the line.

5. Can I use Matlab to find the minimum distance between a point and a line?

Yes, you can use Matlab to find the minimum distance between a point and a line by first calculating the distances of the point from the line using the point2line function, and then using the min function to find the minimum distance.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
375
  • 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
  • Mechanics
Replies
11
Views
287
Back
Top