Matlab help(distance of several points from a line)

  • Context: MATLAB 
  • Thread starter Thread starter supernova1387
  • Start date Start date
  • Tags Tags
    Line Matlab Points
Click For Summary
SUMMARY

The discussion focuses on calculating the minimum distance of multiple points from the line y=x using MATLAB. The user provides a matrix 'a' and successfully computes the distances with the formula d=abs(-a(:,1)+a(:,2))/sqrt(2). However, the user seeks assistance in identifying the specific point in the matrix that corresponds to this minimum distance. The solution involves using the MATLAB command [value, index] = min(d) to retrieve both the minimum distance and the index of the point in matrix 'a'.

PREREQUISITES
  • Basic understanding of MATLAB syntax and matrix operations.
  • Familiarity with distance formulas in geometry.
  • Knowledge of indexing in MATLAB.
  • Experience with MATLAB plotting functions (optional for visualization).
NEXT STEPS
  • Explore MATLAB matrix indexing techniques to enhance data manipulation skills.
  • Learn about MATLAB's built-in functions for distance calculations.
  • Investigate MATLAB plotting functions to visualize points and lines.
  • Study optimization techniques in MATLAB for performance improvements.
USEFUL FOR

Mathematics students, MATLAB users, data analysts, and anyone interested in computational geometry and distance calculations in programming.

supernova1387
Messages
30
Reaction score
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
Code:
[value index] = min(d)
 
jhae2.718 said:
Code:
[value index] = min(d)

Great. Thanks
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
3K
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K