Automatic clustering of data point according to line of best fit
9 views (last 30 days)
Show older comments
Hi All, This is one of this thing easy for an human eyes, but no so easy to code.. I have 2 vector (same length) corresponding to 2 different sensors. i plot them using a scatter plot. See image below. Most of the time the 2 sensors don't read nothing, but sometimes the sensors pick up a signal. Depending on different factor, the sensors can react differently to one another, which means the scatter plot shows multiple lines. (2 in my example, but it can be more, or less...) Does anybody has an idea how to automatically create a function which will take the 2 sensors vector as an input and return a vector the same length which would contain a label corresponding to the line in input data point correspond to?
0 Comments
Answers (1)
KSSV
on 23 May 2018
Given (x,y) data, you can fit s straight line using this:
N = 100 ;
x = rand(N,1) ;
y = rand(N,1) ;
plot(x,y, '.')
% fit a line
coeffs = polyfit(x, y, 1);
% Get fitted values
fittedX = linspace(min(x), max(x), 200);
fittedY = polyval(coeffs, fittedX);
% Plot the fitted line
hold on;
plot(fittedX, fittedY, 'r-')
I have used, a random data, you can use your data.
2 Comments
KSSV
on 23 May 2018
Medric Mainson commented: Hi KSSV, Thanks for your answer. However, i don't think you understand the question. The problem is not to fit a line but to attribute the data point to the line they belong two. Thanks anyway. Cheers
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!