Automatic clustering of data point according to line of best fit

조회 수: 4 (최근 30일)
Mederic Mainson
Mederic Mainson 2018년 5월 23일
댓글: KSSV 2018년 5월 23일
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
KSSV
KSSV 2018년 5월 23일
So, you have mixed data of sensors..and you want to separate them?

댓글을 달려면 로그인하십시오.

카테고리

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