How to compute the correlation coefficient in the two data set.

조회 수: 12 (최근 30일)
mikie
mikie 2022년 11월 16일
답변: Mathieu NOE 2022년 11월 21일
How to compute the correlation coefficient between the two data sets (this is a graphic with 2 function) I need some helps or see any example, and the image is on the paper
  댓글 수: 5
Franco
Franco 2022년 11월 18일
I'm not sure if X= 0,50,10,150,200,250,300,350
Y= 93,94,95,96,97,98,99,100
Mathieu NOE
Mathieu NOE 2022년 11월 21일
hello
FYI we can use grabit to scan the picture and get data

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

답변 (1개)

Mathieu NOE
Mathieu NOE 2022년 11월 21일
hello
so once we have digitized the picture with grabit , we have two data mat files (attached) available for further processing
first step is to make sure the two datasets have common x axis so we must sort out , remove duplicates and interpolate.
then we can compute either one single cor coefficient for the entire data length
%% full data length single cor coeff value
M = corrcoef(y1_new,y2_new);
corcoefficient = M(2,1)
will give : corcoefficient = 0.6209
or make a kind of running buffer version of it
full code :
%% load data
load('Data001.mat')
x1 = Data001(:,1);
y1 = Data001(:,2);
% make sure data are unique and sorted in ascending order
[x1,ind] = sort(x1);
x1 = x1(ind);
y1 = y1(ind);
% remove duplicates
[x1,IA,IC] = unique(x1);
y1 = y1(IA);
load('Data002.mat')
x2 = Data002(:,1);
y2 = Data002(:,2);
% make sure data are unique and sorted in ascending order
[x2,ind] = sort(x2);
x2 = x2(ind);
y2 = y2(ind);
% remove duplicates
[x2,IA,IC] = unique(x2);
y2 = y2(IA);
% interp data on common x axis
x_min = ceil(max(x1(1),x2(1)));
x_max = floor(min(x1(end),x2(end)));
x = x_min:x_max;
y1_new = interp1(x1,y1,x);
y2_new = interp1(x2,y2,x);
%% full data length single cor coeff value
M = corrcoef(y1_new,y2_new);
corcoefficient = M(2,1)
%% running buffer cor coeff value
mybuffer = 10; % nb of samples in one buffer (buffer size)
overlap = mybuffer-1; % overlap expressed in samples
%%%% main loop %%%%
m = length(x);
shift = mybuffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-mybuffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ mybuffer-1,m);
time_index(ci) = floor((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
M = corrcoef(y1_new(start_index:stop_index),y2_new(start_index:stop_index));
corcoefficient(ci) = M(2,1);
end
t2 = x(time_index);
figure(1),
subplot(2,1,1),plot(x,y1_new,x,y2_new);
legend('signal x ','signal y ');
subplot(2,1,2),plot(t2,corcoefficient,'-+r');
legend('cor coefficient');

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by