-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpspm_get_markerinfo.m
86 lines (85 loc) · 2.71 KB
/
pspm_get_markerinfo.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function [sts, markerinfo] = pspm_get_markerinfo(fn, options)
% ● Description
% pspm_get_markerinfo extracts markerinfo from PsPM files that contain
% such information (typically after import of EEG-style data files, e.g.
% BrainVision or NeuroScan)
% ● Format
% [sts, markerinfo] = pspm_get_markerinfo(filename, options)
% ● Arguments
% filename: [char]
% name of PsPM file
% if empty, you will be prompted for one
% ┌────options:
% ├.markerchan: [double]
% │ channel id of the marker channel;
% │ default value: -1, meaning to use the first found marker
% │ channel
% ├──.filename: [char]
% │ name of a file to write the markerinfo to;
% │ default value: empty, meaning no file will be written
% └──overwrite: [logical] (0 or 1)
% Define whether to overwrite existing output files or not.
% Default value: determined by pspm_overwrite.
% ● Output
% sts: [double]
% default value: -1 if unsuccessful
% markerinfo: [struct]
% ├────.name: [char]
% ├───.value:
% └─.element:
% ● History
% Introduced in PsPM 6.0
% Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging)
% Maintained in 2022 by Teddy Chao (UCL)
%% Initialise
global settings
if isempty(settings)
pspm_init;
end
sts = -1;
markerinfo = [];
%% get info
if nargin <= 1
options = struct();
end
options = pspm_options(options, 'get_markerinfo');
% check input arguments
if nargin < 1 || isempty(fn)
fn = spm_select(1, 'mat', 'Extract markers from which file?');
end
if options.markerchan == -1
options.markerchan = 'events';
end
% get file
[bsts, ~, data] = pspm_load_data(fn, options.markerchan);
if bsts == -1, return, end
% check markers
if isempty(data{1}.data)
sts = -1;
warning('File (%s) contains no event markers', fn);
return;
end
%% extract markers: find unique type/value combinations ...
markertype = data{1}.markerinfo.name;
markervalue = data{1}.markerinfo.value;
markerall = strcat(markertype', regexp(num2str(markervalue'), '\s+', 'split'));
markerunique = unique(markerall);
% ... and write them into a struct
for k = 1:numel(markerunique)
% find all elements
indx = find(strcmpi(markerall, markerunique{k}));
% and use first one to extract type and value information
markerinfo(k).name = markertype{indx(1)};
markerinfo(k).value = markervalue(indx(1));
markerinfo(k).elements = indx';
end
% if necessary, write into a file
outfn = options.filename;
if ~isempty(outfn)
ow = pspm_overwrite(outfn, options);
if ow
save(outfn, 'markerinfo');
end
end
sts = 1;
return