Repository navigation
Expand file tree
/
Copy pathpp_05_plot.m
More file actions
59 lines (47 loc) · 1.64 KB
/
Copy pathpp_05_plot.m
File metadata and controls
59 lines (47 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
% 定义IDs和BIDSpath
IDs = {'101', '102', '103'};
BIDSpath = 'D:\ppXinyue\PhdProject\data_fMRI\BIDS\';
% 初始化存储所有被试的rp数据
all_rp_data = cell(length(IDs), 1);
% 遍历每个被试
for i = 1:length(IDs)
ID = IDs{i};
% 构建每个被试的3个rp文件路径
rp01 = [BIDSpath 'sub-' ID '\func\rp_asub-' ID '_task-RG_run-01_bold.txt'];
rp02 = [BIDSpath 'sub-' ID '\func\rp_asub-' ID '_task-RG_run-02_bold.txt'];
rp03 = [BIDSpath 'sub-' ID '\func\rp_asub-' ID '_task-RG_run-03_bold.txt'];
% 读取3个rp文件
rp1 = load(rp01);
rp2 = load(rp02);
rp3 = load(rp03);
% 纵向拼接3个rp文件
all_rp_data{i} = [rp1; rp2; rp3];
end
% 找到所有被试中最短的时间长度
min_length = min(cellfun(@(x) size(x, 1), all_rp_data));
% 截取所有被试的数据到相同长度
for i = 1:length(all_rp_data)
all_rp_data{i} = all_rp_data{i}(1:min_length, :);
end
% 将所有被试的数据拼接成一个三维数组
all_rp_data_3d = cat(3, all_rp_data{:});
% 计算所有被试的rp数据的平均值
mean_rp_data = mean(all_rp_data_3d, 3);
% 画图
figure;
% 第一个子图:前3个头动参数
subplot(2, 1, 1);
plot(mean_rp_data(:, 1:3));
legend('Translation X', 'Translation Y', 'Translation Z');
xlabel('Time Points');
ylabel('Translation (mm)');
ylim([-0.1,0.4])
title('Average Head Motion Parameters (Translation)');
% 第二个子图:后3个头动参数
subplot(2, 1, 2);
plot(mean_rp_data(:, 4:6));
legend('Rotation X', 'Rotation Y', 'Rotation Z');
xlabel('Time Points');
ylabel('Rotation (radians)');
ylim([-0.01,0.01]);
title('Average Head Motion Parameters (Rotation)');