forked from agiahi/ARHMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_nkdata.m
82 lines (73 loc) · 2.74 KB
/
get_nkdata.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
% Created on 3 Mar 2015
% Primary author: Kiefer Forseth
% kjforseth@gmail.com
% 602.531.6430
%
% Summary
% Quickly load any patient & task list.
%
% Input
% paths: struct containing directories generated by get_paths()
% patients: string for single patient | cell list for multiple patients
% tasks: string for single task | cell list for multiple tasks
% task can also be empty string to request default task (common)
% types: string for homogenous list | cell list for mixed list
% can be omitted (defaults to SDE) or set to 'SDE'/'sEEG'
%
% Output
% D: cell of nkdata with size (# patients) x (# tasks)
% if only 1 patient and 1 task passed, output will not be a cell.
% f: cell of nkdata fullpath filenames with same size as D
%
% Example
% ta356 | auditory:
% D = get_nkdata(paths,'ta356','auditory');
% ta356, ta505 | auditory, common
% D = get_nkdata(paths,{'ta356','ta505'},{'auditory','common'};
%
% Change log
% 28 Mar 2015 (KJF): added default task
% 21 Sep 2016 (KJF): removed default task
% 21 Sep 2016 (KJF): added types argument to handle sEEG recordings
% for backward compatibility, lack of types input defaults to SDE
% 13 Oct 2016 (KJF): added filename output (for saving changes to nkdata)
function [D,f] = get_nkdata(paths,patients,tasks,types)
% handle inputs
if ~iscell(patients), patients = {patients}; end
if ~iscell(tasks), tasks = {tasks}; end
if ~exist('types','var'), types = 'SDE'; end % default
if ~iscell(types), types = {types}; end
if length(patients) > 1 && length(types) == 1
[types{1:length(patients),1}] = deal(types{1});
end
% load & store
D = cell(length(patients),length(tasks));
f = cell(length(patients),length(tasks));
for p = 1:length(patients)
patient = patients{p};
type = types{p};
for t = 1:length(tasks)
task = tasks{t};
% handle scramble
if ~isempty(strfind(task,'scr')) && ~strcmp(task,'audscramble')
task = task(1:end-4);
end
% define folder & file location
folder = sprintf('%s%s_lfp_files%s',paths.vol.S1,lower(patient),filesep);
switch type
case 'SDE'
f{p,t} = sprintf('%s%s_%s.mat',folder,patient,task);
case 'sEEG'
f{p,t} = sprintf('%s%s_%s_%s.mat',folder,patient,task,type);
otherwise
error('Unknown recording type')
end
% load & store file
load(f{p,t})
D{p,t} = nkdata;
end
end
% handle output
if ~any(size(D) ~= 1), D = cell2mat(D); end
if ~any(size(f) ~= 1), f = cell2mat(f); end
%if strcmp(patient,'ta510'), D={D,aoff};end