This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_nb_vol.m
56 lines (43 loc) · 1.51 KB
/
check_nb_vol.m
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
% small script to check the number of volumes in each bold file for each task
clear;
close all;
clc;
tgt_dir = 'D:\Dropbox\BIDS\olf_blind\raw';
spm_path = 'D:\Dropbox\Code\MATLAB\Neuroimaging\SPM\spm12';
addpath(spm_path);
spm('defaults', 'fmri');
BIDS = spm_BIDS(tgt_dir);
tasks = spm_BIDS(BIDS, 'tasks');
subjects = spm_BIDS(BIDS, 'subjects');
types = spm_BIDS(BIDS, 'types');
for iTask = 1:numel(tasks)
all_tasks(iTask) = struct('nb_run', [], 'nb_vol', []);
end
for iSubject = 1:numel(subjects)
disp(subjects{iSubject});
for iTask = 1:numel(tasks)
runs = spm_BIDS(BIDS, 'runs', ...
'sub', subjects{iSubject}, ...
'task', tasks{1, iTask}, ...
'type', 'bold');
files = spm_BIDS(BIDS, 'data', ...
'sub', subjects{iSubject}, ...
'task', tasks{1, iTask}, ...
'type', 'bold');
hdr = spm_vol(files);
all_tasks(iTask).nb_run = [all_tasks(iTask).nb_run str2double(runs)];
all_tasks(iTask).nb_vol = [all_tasks(iTask).nb_vol cellfun(@numel, hdr)']; %#ok<*SAGROW>
end
end
%%
close all;
for iTask = 1:numel(tasks)
figure('name', tasks{iTask}, 'position', [25 50 1500 600]);
bar(all_tasks(iTask).nb_vol);
axis tight;
set(gca, ...
'xtick', find(all_tasks(iTask).nb_run == 1), ...
'xticklabel', subjects, ...
'fontsize', 8);
title(sprintf('Number of volumes in task: %s', tasks{iTask}));
end