/ concept-collection / seqlab
Sign in
concept-collection / seqlab
seqlab / src / engine / pulseq / +mr / block2events.m
48 lines · 1.3 KBBlameHistoryRaw
1function c = block2events(b)
2%BLOCK2EVENTS Convert a block structure to cell array.
3% c=BLOCK2EVENTS(b) Convert the block structure to cell of
4% sequence events.
5%
6% If b is already a cell array of events this array is
7% returned unmodified.
8
9% strip away 1x1 cell wrapper(s) -- otherwise it conflicts with adding ready-made blocks
10while iscell(b) && 1==length(b) && iscell(b{1})
11 b=b{1};
12end
14c = b; % Assume b is already a cell array of events
15if iscell(b)
16 first = b{1}; % Use first element to test for block structure
17else
18 first = b;
19end
20if isfield(first, 'rf')
21 % Argument is a block structure, copy events to cell array
22 % varargin for further processing.
23 assert(length(b) == 1, 'Only a single block structure can be added');
24% fields = fieldnames(first)';
25%%%%%%%
26% c = {};
27% for f = fields
28% if ~isempty(first.(char(f)))
29% c{end+1} = first.(char(f));
30% end
31% end
32%%
33% c = cell(1,length(fields));
34% for i = 1:length(fields)
35% c{i} = first.(char(fields(i)));
36% end
37 c=struct2cell(first);
38 %c(cellfun(@isempty,c))=[];
39 c(cellfun('isempty',c))=[];
40 %c=c(~cellfun('isempty',c));
42 %c(cellfun('isnumeric',c))=[]; % remove blockDuration
44elseif iscell(first)
45 c = first;
46end
48end
moveopenescclose