필터 지우기
필터 지우기

How to find the linear regression of two data sets with different times and different size?

조회 수: 28 (최근 30일)
I have two data sets:
A = [27 30 28 32 30] 1x5 double
that is measured during the time
Time_A=[00:38:00 00:39:00 00:40:00 00:41:00 00:42:00] 1x5 double
And B =[27 28 32 38 28 29 30 32 ] 1x8 double
measured during the time
Time_B=[00:40:30 00:41:30 00:42:30 00:43:30 00:43:30 00:44:30 00:45:30] 1x8 double
How can I find the linear regression? They have different size and the time doesn't match because they are collected from different instruments.
Thank you

채택된 답변

Tim
Tim 2020년 11월 6일
It's not entirely clear what you are asking: are you asking how to perform a linear regression on the dataset formed by combining both sets of measurements and times? (By the way: it looks like there are only seven values in your second set of time stamps.) If so, just combine the time and measurement vectors and use Matlab's "polyfit" like in the following example. I'm making "A" your measurements from instrument 1 and AT your time stamps from set 1, and "B" your measurements from instrument 2 and BT the time stamps from instrument 2:
figure;
% Time vector, set 1
AT = 38:42;
% Measurements set 1 (simulated)
A = randn(size(AT)) + 0.1*(38:42); % Noise plus some slope
% Time vector, set 2
BT = (40:47) + 0.5;
% Measurements set 2 (simulated)
B = randn(size(BT)) + 0.1*(40:47); % Noise plus same slope
% Combine measurements and times
measurements = [A, B];
times = [AT, BT];
% Plot
plot(times, measurements, 'k.');
% Linear regression
P = polyfit(times, measurements, 1);
% Plot result
hold on;
plot(times, polyval(P, times), 'k');
hold off;
P has your regression coefficients, P(1) will be the slope (should be about ~0.1, gets better with more measurements) and P(2) should be the offset.
  댓글 수: 3
Tim
Tim 2020년 11월 9일
편집: Tim 2020년 11월 9일
Then this, or this maybe what you are looking for.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by