-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadfile.m
61 lines (52 loc) · 1.9 KB
/
loadfile.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
function d = loadfile(filename)
%LOADFILE A function to load MAT files created by acq2mat.py.
%
% USAGE: d = loadfile(filename);
%
% Brandon Cummings
% MCIRCC, University of Michigan, Ann Arbor
% June 4, 2019
%
% The loadfile() function reads a MAT file constructed by acq2mat.py and
% reconfigures the event_markers field into a MATLAB table. This is
% necessary because the scipy.io.savemat() function only supports
% structural data, not tabular.
%
% The output is an object, 'd', is a MATLAB structure with fields
% corresponding to the Biopac channel names. Each of the channels is a
% structure in its own right, with subfields "wave", "Fs", and "unit". The
% "wave" object contains the waveform data in an column vector with double
% precision. The "Fs" object represents the sampling frequency in Hz, and
% the "unit" is a character object describing the unit of measure. Note
% that this is reflective of what is entered manually in Biopac, and has
% historically not been kept up-to-date through template changes.
%
% EXAMPLES
%
% 1. Plot arterial pressure waveform saved under the channel name "abp"
%
% d = loadfile(filename);
% plot( (1:length(d.abp.wave))/d.abp.Fs, d.abp.wave)
% xlabel('Time (seconds)')
% ylabel(sprintf('ABP (%s)', d.abp.unit))
%
% 2. Annotate with event markers
%
% text(d.event_markers.sample_index/Fs, ...
% zeros(height(d.event_markers), 1), ...
% d.event_markers.label, ...
% 'Rotation', 90)
%
load(filename, 'd');
fields = fieldnames(d.event_markers);
for i = 1:numel(fields)
% Convert character arrays to cellstr
if isa(d.event_markers.(fields{i}), 'char')
d.event_markers.(fields{i}) = cellstr(d.event_markers.(fields{i}));
% Convert in64 to doubles
elseif isa(d.event_markers.(fields{i}), 'int64')
d.event_markers.(fields{i}) = double(d.event_markers.(fields{i}));
end
end
d.event_markers = struct2table(d.event_markers);
end