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?

0 件のコメント
回答 (1 件)
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
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 Center および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!