-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbf_load.m
38 lines (30 loc) · 1.12 KB
/
bf_load.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
function BF = bf_load(file, fields)
% Loads BF data into memory with just the requested fields
% Copyright (C) 2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
% $Id: bf_load.m 131 2015-08-19 16:04:20Z [email protected] $
% get filename
%-------------------------------------------------------------------------
if nargin == 0
[file, sts] = spm_select(1, '^BF.mat$', 'Select BF.mat file');
if ~sts, BF = []; return; end
end
vars = whos('-file', file);
if numel(intersect({vars(:).name}, bf_std_fields)) == 0
error('No BF fields in the file');
end
% load MAT file
%--------------------------------------------------------------------------
if nargin <= 1
BF = load(file);
else
if ~iscell(fields)
fields = {fields};
end
BF = load(file, fields{:});
end
[sel1, sel2] = spm_match_str(bf_std_fields, fieldnames(BF));
[other_fields, sel3] = setdiff(fieldnames(BF), bf_std_fields);
[other_fields_sorted, sel4] = sort(other_fields);
tmpcell = struct2cell(BF);
BF = cell2struct(tmpcell([sel2 sel3(sel4)]), [bf_std_fields(sel1) other_fields_sorted], 1);