[422372]: / functions / popfunc / eeg_oldica.m

Download this file

133 lines (121 with data), 5.1 kB

  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
% EEG_OLDICA - report, return or add to oldicaweights and oldicasphere
% stored in cell arrays in EEG.etc of an EEGLAB dataset
% Usage:
% >> eeg_oldica(EEG); % report number of stored oldicaweights
% >> [EEG,icaweights, icasphere] = eeg_oldica(EEG,N); % return matrices
% >> EEG = eeg_oldica(EEG,N,icaweights,icasphere); % add wts and sph
% % matrices to EEG.etc.icaweights and EEG.etc.icasphere
% Inputs:
% EEG - EEGLAB dataset structure
% nreturn - index of the oldicaweights and sphere to return {default: 1}
% icaweights - ICA weights matrix to store in EEG.etc.oldicaweights
% icasphere - ICA sphere matrix to store in EEG.etc.oldicasphere
% Outputs:
% icaweights - ICA unmixing matrix (e.g., EEG.icaweights)
% icasphere - ICA data sphering matrix (e.g., EEG.icasphere)
%
% See also: POP_RUNICA
%
% Author: Scott Makeig, SCCN/INC/UCSD, March 17, 2005
% Copyright (C) 2004 Scott Makeig, SCCN/INC/UCSD, smakeig@ucsd.edu
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
function [EEG,oldicaweights,oldicasphere] = eeg_oldica(EEG, nreturn,icaweights,icasphere)
if nargin< 1
help eeg_oldica
return
end
if ~isstruct(EEG)
error('EEG argument must be a dataset structure')
end
if ~isfield(EEG,'etc')
error('EEG.etc field not found - no old ICA weights in dataset');
end
if ~isfield(EEG.etc,'oldicaweights') && nargin < 3
error('EEG.etc.oldicaweights field not found - no old ICA weights in dataset');
elseif nargout < 2 && nargin < 3
if length(EEG.etc.oldicaweights) > 1
fprintf('EEG.etc.oldicaweights contains %d weight matrices\n',length(EEG.etc.oldicaweights));
EEG.etc.oldicaweights
else
fprintf('EEG.etc.oldicaweights contains %d weight matrix\n',length(EEG.etc.oldicaweights));
EEG.etc.oldicaweights
end
end
if ~isfield(EEG.etc,'oldicasphere') && nargin < 3
fprintf('EEG.etc.oldicasphere field not found - no old ICA sphere matrix in dataset');
elseif nargout < 2 && nargin < 3
fprintf('\n');
if length(EEG.etc.oldicasphere) > 1
fprintf('EEG.etc.oldicasphere contains %d weight matrices\n',length(EEG.etc.oldicasphere));
EEG.etc.oldicasphere
else
fprintf('EEG.etc.oldicasphere contains %d weight matrix\n',length(EEG.etc.oldicasphere));
EEG.etc.oldicasphere
end
fprintf('\n');
end
if nargin < 2
nreturn = 1;
elseif nargin < 3
if nreturn< 1
error('nreturn must be an oldicaweights index');
elseif length(EEG.etc.oldicaweights) < nreturn
fprintf('nreturn (%d) > number of stored oldicaweights (%d) ', nreturn,length(EEG.etc.oldicaweights));
error(' ');
end
end
if nargin > 4
error('too many arguments.\n');
end
if nargin > 2
if nargout > 0
fprintf('New EEG.etc.oldicaweights: ');
EEG.etc.oldicaweights = [EEG.etc.oldicaweights {icaweights}];
EEG.etc.oldicaweights
else
error('To update oldicaweights, at least one output required');
end
end
if nargin > 3
fprintf('New EEG.etc.oldicasphere: ');
EEG.etc.oldicasphere = [EEG.etc.oldicasphere {icasphere}];
EEG.etc.oldicasphere
end
if nargout > 1
% fprintf('\n');
oldicaweights = EEG.etc.oldicaweights{nreturn};
% fprintf('Stored oldicaweights matrix (%d) returned (%d,%d).\n',nreturn,size(oldicaweights,1),size(oldicaweights,2));
if length(EEG.etc.oldicasphere) >= nreturn
oldicasphere = EEG.etc.oldicasphere{nreturn};
% fprintf('Stored oldicasphere matrix (%d) returned (%d,%d).\n',nreturn,size(oldicasphere,1),size(oldicasphere,2));
else
oldicasphere = [];
% fprintf('No corresponding oldicasphere matrix; [] returned.\n');
end
% fprintf('\n');
end
return