Automatic clustering of data point according to line of best fit

4 次查看(过去 30 天)
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?

回答(1 个)

KSSV
KSSV 2018-5-23
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 个评论
KSSV
KSSV 2018-5-23
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品


版本

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by