Switch to unified view

a b/functions/@eegobj/subsasgn.m
1
function this = subsasgn(this,index,c)
2
3
    if isempty(this)
4
        this = eegobj;
5
    end
6
        
7
    % multiple dataset
8
    if strcmpi(index(1).type, '()') && length(index) == 1 % dataset assignment
9
        if isempty(c) % suppression
10
            this(index.subs{1}) = [];
11
        else
12
            % create empty structures if necessary
13
            % not optimized for speed but compatible Octave 3.4 and Matlab
14
            allfieldsori = fieldnames( this );
15
            allSetIndices = [ [(length(this)+1):(min(index.subs{1})-1)] index.subs{1} ];
16
            this(max(index.subs{1})) = this(1);
17
            for j = 1:length(allfieldsori)
18
                for i = allSetIndices
19
                    this(i).EEG.(allfieldsori{j}) = [];
20
                end
21
            end
22
            
23
            % create empty structure, replaces the code above but
24
            % only compatible under Matlab
25
            %allfieldsori = fieldnames( this );
26
            %tmpfields = allfieldsori;
27
            %tmpfields(:,2) = cell(size(tmpfields));
28
            %tmpfields = tmpfields';
29
            %tmp = struct(tmpfields{:})
30
            %this(index.subs{1}) = tmp;
31
            
32
            % dealing with input object and making it a compatible
33
            % structure 
34
            if isa(c, 'eegobj')
35
                c2 = struct(c);
36
                c  = c2(1).EEG;
37
                fieldorder = fieldnames(c);
38
                for cIndexe = 2:length(c2)
39
                    c(cIndexe) = orderfields(c2(cIndexe).EEG, fieldorder);
40
                end
41
            end
42
            
43
            allfields = fieldnames( c );
44
            for i=1:length( allfields )
45
                for j = 1:length(index.subs{1})
46
                    this(index.subs{1}(j)).EEG.(allfields{i}) = c(min(j, length(c))).(allfields{i});
47
                end
48
                %this(index.subs(1)).EEG = setfield(this(index.subs(1)).EEG, getfield(c, allfields{i}), allfields{i});
49
                %eval( ['this(' int2str(index.subs{1}) ').' allfields{i} ' = c.' allfields{i} ';' ]);
50
            end;    
51
            %if ~isfield(c, 'datfile') & isfield(this, 'datfile')
52
            %    this(index.subs{1}).datfile = '';
53
            %end
54
        end
55
    elseif strcmpi(index(1).type, '()')
56
        if length(index(1).subs{1}) > 1
57
            error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays');
58
        elseif length(this) < index(1).subs{1}
59
            this(index(1).subs{1}) = eegobj;
60
        end
61
        this(index(1).subs{1}).EEG = builtin('subsasgn', this(index(1).subs{1}).EEG, index(2:end), c);
62
    elseif strcmpi(index(1).type, '.')
63
        if length(this) > 1
64
            error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays');
65
        else
66
            this.EEG = builtin('subsasgn', this.EEG, index, c);
67
        end
68
    end