What am I doing wrong with my MATLAB script calculating PRx (pressure reactivity index)?

I need to calculate PRx (pressure reactivity index) using ICP (intracranial pressure) and mean ABP/MAP (mean arterial blood pressure) data. PRx is known as “pressure reactivity index is calculated as the degree of statistical correlation between the slow wave components of mean arterial pressure (ABP or MAP) and intracranial pressure (ICP)”. I need to do this in order to calculate a different hypothetical reactivity index. I have PRx data- so my idea was to use the given PRx data and compare it to the calculated PRx data to ensure it is correct.

This is the script to display the PRx data that was given to me:

%PRx_display

% Load PRx data from MAT file
load('PRx,data_part1of1');

PRx_values = measurement_data;

disp('PRx Values:');
disp(PRx_values);

% Plot PRx values
figure;
plot(PRx_values);
xlabel('Time');
ylabel('PRx Value');
title('PRx');
grid on;

% Calculate average PRx
average_PRx = mean(PRx_values);

% Display average PRx
fprintf('Average PRx: %.4f\n', average_PRx);

This is the script I am trying to calculate PRx with:

%PRx_calc

% Load ICP and MAP data
load("ICP,data_part1of1");
ICP_time_vector = round(time_vector); % Assuming time_vector in ICP file
ICP_data = measurement_data;

load("ABP,mean,data_part1of1");
ABP_time_vector = round(time_vector); % Assuming time_vector in ABP file
ABP_data = measurement_data;

% Remove duplicate time points from ICP
[ICP_time_vector, uniqueIdx] = unique(ICP_time_vector);
ICP_data = ICP_data(uniqueIdx);

% Remove duplicate time points from ABP
[ABP_time_vector, uniqueIdx] = unique(ABP_time_vector);
ABP_data = ABP_data(uniqueIdx);

% Ensure consistent dimensions
if length(ICP_time_vector) ~= length(ICP_data)
error('ICP_time_vector and ICP_data have different lengths');
end

if length(ABP_time_vector) ~= length(ABP_data)
error('ABP_time_vector and ABP_data have different lengths');
end

% Interpolating ABP to match ICP time vector
if ~isequal(ICP_time_vector, ABP_time_vector)
ABP_data = interp1(ABP_time_vector, ABP_data, ICP_time_vector, 'linear', 'extrap');
end

% Combine ICP data and aligned ABP data
ICP = [ICP_time_vector(:), ICP_data(:)]; % Ensure column vectors
ABP = [ICP_time_vector(:), ABP_data(:)]; % ABP_data is now interpolated to match ICP_time_vector

% Parameters
windowSize = 30 * 10; % 30 windows of 10 seconds
stepSize = 60; % Update every 60 seconds
n = length(ICP_time_vector); % Number of data points

% Preallocate PRx array
PRx = NaN(floor((n - windowSize) / stepSize) + 1, 1);

% Compute moving correlation coefficient
for i = 1:stepSize:(n - windowSize + 1)
% Extract current window of data
windowICP = ICP(i:i + windowSize - 1, 2);
windowABP = ABP(i:i + windowSize - 1, 2);

    % Calculate correlation coefficient for the current window
    R = corrcoef(windowICP, windowABP);
    
    % Store PRx (correlation coefficient of ICP and ABP)
    PRx(floor(i / stepSize) + 1) = R(1, 2);

end

% Calculate average PRx ignoring NaN values
averagePRx = sum(PRx, 'omitnan') / sum(~isnan(PRx));

% Display average PRx in the command window
fprintf('Average PRx: %.4f\n', averagePRx);

% Plot PRx vs Time in minutes
figure;
plot((0:length(PRx)-1)*stepSize/60, PRx); % Convert to minutes
title('PRx vs Time');
xlabel('Time (minutes)');
ylabel('PRx Values');

I thought the calculation script would work, but it doesn’t. For instance, for a certain set of data, PRx_calc.m gives me an average PRx value of 0.32, while PRx_display.m gives me 0.52. The trend of the plots look the same, but the PRx_calc.m’s for some reason looks shifted down and distorted a little bit.
I am looking for help with the way I am using the corrcoef function and general debugging help.

Here are the first 20 values of each type of data:
First 20 values of ICP:
10
10
10
10
11
11
11
11
10
11
10
11
11
11
11
11
10
11
11
11

First 20 values of ABP:
89
89
89
89
89
89
89
89
89
89
89
89
89
89
89
89
89
89
89
89

First 20 calculated PRx values:
NaN
NaN
NaN
NaN
NaN
NaN
-0.0838
-0.2111
-0.0586
0.1704
0.4276
0.3193
0.3417
0.4128
0.5488
0.4790
0.5207
0.6822
0.7107
0.5235

The PRx_calc script, which produces the above values, should produce the given PRx values(below).

First 20 PRx Values:
0.6150
0.5996
0.6010
0.6276
0.7499
0.4495
0.4488
0.4492
0.5078
0.7263
0.7290
0.7343
0.7490
0.7561
0.6997
0.4609
0.2567
0.5935
0.7317
0.6666

New contributor

calebcarp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật