-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpar_concatSteps.m
67 lines (63 loc) · 1.7 KB
/
par_concatSteps.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
function P = par_concatSteps(A,fields);
% P = par_concatSteps(steps);
% P = par_concatSteps(filebasename);
% ..., whichFields);
%
% concatenates steps variable by variable into a single structure P that's
% easier to analyze.
% either takes the steps from a vector of structures, or from a sequence of
% files filebasename1.mat, filebasename2.mat,...
if isstruct(A) % series of steps stored in a variable --------------------------
N = length(A);
if nargin < 2
fields = fieldnames(A(1));
end
for i=1:length(fields)
if ~strcmpi(fields{i},'profiles')
P.(fields{i}) = nan.*ones([N size(A(1).(fields{i}))]);
end
end
for n=1:N
for i=1:length(fields)
if ~strcmpi(fields{i},'profiles')
P.(fields{i})(n,:) = A(n).(fields{i})(:);
else
pro = fieldnames(A(n).profiles);
for j=1:length(pro)
P.profiles.(pro{j})(n,:,:) = A(n).profiles.(pro{j});
end
end
end
end
elseif ischar(A) % series of files ---------------------------------------------
thefiles = dir([A '*.mat']);
filenames = {thefiles.name};
if isempty(filenames)
warning(['no files found at ' A '*.mat']);
end
N = length(filenames);
load(filenames{1},'step');
if nargin < 2
fields = fieldnames(step);
end
for i=1:length(fields)
if ~strcmpi(fields{i},'profiles')
P.(fields{i}) = nan.*ones([N size(step.(fields{i}))]);
end
end
for n=1:N
load(filenames{n},'step');
for i=1:length(fields)
if ~strcmpi(fields{i},'profiles')
P.(fields{i})(n,:) = step.(fields{i})(:);
else
pro = fieldnames(step.profiles);
for j=1:length(pro)
P.profiles.(pro{j})(n,:,:) = step.profiles.(pro{j});
end
end
end
end
else
error('neither a structure nor a string.');
end