Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

how to filter points which are on a straight line

Asked by Itzik Ben Shabat on 7 Mar 2013

hi, im looking for a function that will allow me to filter all points that are on a straight line and keep the points that represent that lines ends. for example if im given [1 1; 2 2; 3 3; 4 5; 5 5; 6 6; 7 7] than the output should be [1 1;3 3;4 5;5 5; 7 7] it filters 2 2 since its on the line between 1 1 and 3 3 and also filters 6 6 because its on the line between 5 5 and 7 7 can anyone help? thanks

0 Comments

Itzik Ben Shabat

Products

No products are associated with this question.

2 Answers

Answer by Image Analyst on 7 Mar 2013

Depending on what you want to do and what your data look like, you may need to use RANSAC: http://en.wikipedia.org/wiki/Ransac It can find lines in a mess of points, like this:

0 Comments

Image Analyst
Answer by Teja Muppirala on 7 Mar 2013
F = [1 1; 2 2; 3 3; 4 5; 5 5; 6 6; 7 7];
dydx = diff(F(:,2))./diff(F(:,1));
F(1 + find(diff(dydx)==0) ,:) = []

1 Comment

Teja Muppirala on 7 Mar 2013

This assumes they are EXACTLY on a straight line. But floating-point math can sometimes mess that up, so you might want to do

abs(diff(dydx)) < some small tolerance

instead of just

diff(dydx) == 0

Teja Muppirala

Contact us