diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 000000000..e6a539389 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,2 @@ +[codespell] +ignore-words-list = alls,aussian,childs,datas,dum,ede,espacing,fastr,fo,hist,htmp,leaded,linke,mapp,nd,nwe,ois,ot,otu,pres,ro,ser,strng,sxl,whos diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..2e3038793 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,40 @@ +--- +name: Bug report +about: Create a report to help us improve EEGLAB +title: '' +labels: '' +assignees: '' + +--- + +### Description + +[*Description of the bug or feature +Attach a link to Dropbox or Google Drive with screenshots and your data if possible.*] + +
+#### Steps to Reproduce + +1. [*First Step*] +2. [*Second Step*] +3. [*and so on...*] + + +
+#### Expected behavior: +[*What you expected to happen*] + + +
+#### Actual behavior: +[*What actually happened*] + + +
+#### Versions + +| | | +|----| ---- | +| OS version | [*fill in*] | +| Matlab version | [*fill in*] | +| EEGLAB version | [*fill in*] | diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5cf41595e --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# ignore everything in plugin folders, but keep track of plugin submodules +*.asv +/plugins/** +!/plugins/clean_rawdata +!/plugins/dipfit +!/plugins/firfilt +!/plugins/ICLabel +.DS_Store diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..592e3efa0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,15 @@ +[submodule "plugins/dipfit"] + path = plugins/dipfit + url = https://github.com/sccn/dipfit.git +[submodule "plugins/clean_rawdata"] + path = plugins/clean_rawdata + url = https://github.com/sccn/clean_rawdata.git +[submodule "plugins/ICLabel"] + path = plugins/ICLabel + url = https://github.com/sccn/ICLabel +[submodule "tutorial_scripts"] + path = tutorial_scripts + url = https://github.com/sccn/eeglab_tutorial_scripts.git +[submodule "plugins/firfilt"] + path = plugins/firfilt + url = https://github.com/sccn/firfilt diff --git a/1ST_README.txt b/1ST_README.txt deleted file mode 100644 index 3223bde00..000000000 --- a/1ST_README.txt +++ /dev/null @@ -1,47 +0,0 @@ - -This dir contains original Matlab functions from the EEGLAB (formerly ICA/EEG) -Matlab toolbox, all released under the Gnu public license (see eeglablicence.txt). -See the EEGLAB tutorial and reference paper (URLs given below) for more information. - -Sub-directories: - - /functions - All distributed EEGLAB functions (admin, sigproc, pop, misc) - /plugins - Directory to place all downloaded EEGLAB plug-ins. dipfit (1.0) - is present by default - /sample_data - Miscellaneous EEGLAB data using in tutorials and references - /sample_locs - Miscellaneous standard channel location files (10-10, 10-20) - See the EEGLAB web site http://sccn.ucsd.edu/eeglab/ for more. - -To use EEGLAB: - -1. Place the Matlab functions in a directory ($DIR) and add - $DIR/eeglab4.x to (Unix) your matlabpath environment variable. - Else, within Matlab - >> addpath('full_path_here') - -2. Optional: Edit file "icadefs.m" under the function directory to specify the location of - the faster binary "ica" function (equivalent to Matlab runica() and called from within - Matlab by binica()). This requires a (recommended) separate download from - http://sccn.ucsd.edu/eeglab/binica/ - Also add the path to the EEGLAB tutorial. This requires another (recommended) download. See - http://sccn.ucsd.edu/eeglab/ - File "icadefs.m" also specifies various limits and constants used in EEGLAB functions. - -3. Then start Matlab and type >> eeglab - -4. Open the main EEGLAB tutorial page (your downloaded "eeglabtut.html", - else browse http://sccn.ucsd.edu/eeglab/eeglabtut.html) - -5. Please send feedback and suggestions to: eeglab@sccn.ucsd.edu - -6. In publications, please reference: - -Delorme, A., Makeig, S. (in press) EEGLAB: An open source toolbox for analysis of single-trial -EEG dynamics including independent component analysis. Journal of Neuroscience Methods. - http://sccn.ucsd.edu/eeglab/download/eeglab_jnm03.pdf - -Enjoy using EEGLAB to explore and analyze your data. Consider contributing to your functions -and creativity to EEGLAB open source development (see http://sccn.ucsd.edu/eeglab for more details). - -Arno Delorme & Scott Makeig -Fri Sep 6 11:44:29 PDT 2002 diff --git a/Contents.m b/Contents.m index 1c86dfa8e..8f45b59c7 100644 --- a/Contents.m +++ b/Contents.m @@ -1,5 +1,5 @@ % EEGLAB Toolbox to process EEG data -% Version 13.x (dev) +% Version - see eeg_getversion() % % eeglab() - Matlab graphic user interface environment for % electrophysiological data analysis incorporating the ICA/EEG toolbox diff --git a/README.md b/README.md new file mode 100644 index 000000000..d2e0032f7 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +[![GitHub issues](https://img.shields.io/github/issues/sccn/eeglab?color=%23fa251e&logo=GitHub)](https://github.com/sccn/eeglab/issues) +![Twitter Follow](https://img.shields.io/twitter/follow/eeglab2?style=social) + +# What is EEGLAB? +EEGLAB is an open source signal processing environment for electrophysiological signals running on Matlab and Octave (command line only for Octave). This folder contains original Matlab functions from the EEGLAB (formerly ICA/EEG) Matlab toolbox, all released under the Gnu public license (see eeglablicence.txt). See the EEGLAB tutorial and reference paper (URLs given below) for more information. + +# Installing/cloning +**Recommended:** Download the official EEGLAB release from https://sccn.ucsd.edu/eeglab/download.php + +**Do not download a ZIP file directly from GIT as it will not contain EEGLAB submodules**. Instead clone the reposity while pulling EEGLAB sub-modules. + +``` +git clone --recurse-submodules https://github.com/sccn/eeglab.git +``` + +If you forgot to clone the submodule, go to the eeglab folder and type + +``` +git submodule update --init --recursive --remote +git pull --recurse-submodules +``` + +# Sub-directories: + + - /functions - All distributed EEGLAB functions (admin, sigproc, pop, misc) + - /plugins - Directory to place all downloaded EEGLAB plug-ins. dipfit (1.0) is present by default + - /sample_data - Miscellaneous EEGLAB data using in tutorials and references + - /sample_locs - Miscellaneous standard channel location files (10-10, 10-20). See the EEGLAB web site http://sccn.ucsd.edu/eeglab/ for more. + +# To use EEGLAB: + +1. Start Matlab + +2. Use Matlab to navigate to the folder containing EEGLAB + +3. Type "eeglab" at the Matlab command prompt ">>" and press enter + +3. Open the main EEGLAB tutorial page (http://sccn.ucsd.edu/wiki/EEGLAB_Wiki) + +4. Please send feedback and suggestions to: eeglab@sccn.ucsd.edu + +# In publications, please reference: + +Delorme, A., & Makeig, S. (2004). EEGLAB: an open source toolbox for analysis of single-trial EEG dynamics including independent component analysis. Journal of neuroscience methods, 134(1), 9-21. (See article [here](http://sccn.ucsd.edu/eeglab/download/eeglab_jnm03.pdf)) + +# Compiled version of EEGLAB + +If you experience problems, try running EEGLAB as administrator. + +# Documentation: + +EEGLAB documentation is available on the EEGLAB wiki (see http://sccn.ucsd.edu/wiki/EEGLAB_Wiki for more details). diff --git a/eeglab.m b/eeglab.m index 34d30c86c..a7f7432a8 100644 --- a/eeglab.m +++ b/eeglab.m @@ -8,8 +8,8 @@ % % Authors: Arnaud Delorme and Scott Makeig, with substantial contributions % from Colin Humphries, Sigurd Enghoff, Tzyy-Ping Jung, plus -% contributions -% from Tony Bell, Te-Won Lee, Luca Finelli and many other contributors. +% contributions from Tony Bell, Te-Won Lee, Luca Finelli and many +% other contributors. % % Description: % EEGLAB is Matlab-based software for processing continuous or event-related @@ -24,14 +24,15 @@ % % Usage: 1) To (re)start EEGLAB, type % >> eeglab % Ignores any loaded datasets +% >> eeglab nogui % Do not pop up GUI % 2) To redaw and update the EEGLAB interface, type % >> eeglab redraw % Scans for non-empty datasets % >> eeglab rebuild % Closes and rebuilds the EEGLAB window % >> eeglab versions % State EEGLAB version number % -% >> type "license.txt" % the GNU public license -% >> web http://sccn.ucsd.edu/eeglab/tutorial/ % the EEGLAB tutorial -% >> help eeg_checkset % the EEG dataset structure +% >> type "eeglablicense.txt" % the EEGLAB open source license +% >> web http://eeglab.org % the EEGLAB tutorial +% >> help eeg_checkset % the EEG dataset structure % % GUI Functions calling eponymous processing and plotting functions: % ------------------------------------------------------------------ @@ -42,9 +43,6 @@ % pop_epoch - extract epochs from a continuous dataset (epoch()) % pop_erpimage - plot single epochs as an image (erpimage()) % pop_jointprob - reject epochs using joint probability (jointprob()) -% pop_loaddat - load Neuroscan .DAT info file (loaddat()) -% pop_loadcnt - load Neuroscan .CNT data (lndcnt()) -% pop_loadeeg - load Neuroscan .EEG data (loadeeg()) % pop_loadbva - load Brain Vision Analyser matlab files % pop_plotdata - plot data epochs in rectangular array (plotdata()) % pop_readegi - load binary EGI data file (readegi()) @@ -120,71 +118,131 @@ % eeg_helppop - help on pop_ and eeg_ functions % eeg_helpsigproc - help on -% Copyright (C) 2001 Arnaud Delorme and Scott Makeig, Salk Institute, +% Copyright (C) 2001 Arnaud Delorme and Scott Makeig, Salk Institute, % arno@salk.edu, smakeig@ucsd.edu. % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% Copyright (C) 2001 Arnaud Delorme, SCCN/INC/UCSD, arno@salk.edu % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 varargout = eeglab( onearg ) +persistent warningShowed; + +ver = version; +if strcmpi(ver, '9.4.0.813654 (R2018a)') + disp('Link to install 2018a Update 2'); + errordlg( [ 'You are running Matlab version R2018a, which has important bugs' 10 'Matlab crashes when running EEGLAB in this version of Matlab' 10 'Install 2018a Update 2 to fix the issue (link on the command line)' ]); +end + if nargout > 0 varargout = { [] [] 0 {} [] }; - %[ALLEEG, EEG, CURRENTSET, ALLCOM] -end; +end + +% Warning if in toolbox folder +% ---------------------------- +if isempty(warningShowed) + filterPath = fileparts(fileparts(fileparts(which('filter')))); + eeglabPath = fileparts(fileparts(which('eeglab'))); + if ~isempty(strfind(filterPath, eeglabPath)) + fprintf(2, 'Warning: EEGLAB is in the MATLAB toolbox folder which is not recommended\n'); + fprintf(2, ' You may experience errors if a plugin overloads a MATLAB function\n'); + end + warningShowed = true; +end % check Matlab version % -------------------- vers = version; +indp = find(vers == '.'); +if str2num(vers(indp(1)+1)) > 1, vers = [ vers(1:indp(1)) '0' vers(indp(1)+1:end) ]; end +indp = find(vers == '.'); +vers = str2num(vers(1:indp(2)-1)); tmpv = which('version'); if ~isempty(findstr(lower(tmpv), 'biosig')) - [tmpp tmp] = fileparts(tmpv); + [tmpp, ~] = fileparts(tmpv); rmpath(tmpp); -end; -if str2num(vers(1)) < 7 && str2num(vers(1)) >= 5 - tmpWarning = warning('backtrace'); - warning backtrace off; - warning('You are using a Matlab version older than 7.0'); +end +% remove freemat folder if it exist +tmpPath = fileparts(fileparts(which('sread'))); +newPath = fullfile(tmpPath, 'maybe-missing', 'freemat3.5'); +if exist(newPath) == 7 + warning('off', 'MATLAB:rmpath:DirNotFound'); + rmpath(newPath) + warning('on', 'MATLAB:rmpath:DirNotFound'); +end +if ismatlab && vers < 7 + tmpWarning = warning('query', 'backtrace'); + warning('off', 'backtrace'); warning('This Matlab version is too old to run the current EEGLAB'); warning('Download EEGLAB 4.3b at http://sccn.ucsd.edu/eeglab/eeglab4.5b.teaching.zip'); warning('This version of EEGLAB is compatible with all Matlab version down to Matlab 5.3'); - warning(tmpWarning); + warning(tmpWarning.state, 'backtrace'); return; -end; - -% check Matlab version -% -------------------- -vers = version; -indp = find(vers == '.'); -if str2num(vers(indp(1)+1)) > 1, vers = [ vers(1:indp(1)) '0' vers(indp(1)+1:end) ]; end; -indp = find(vers == '.'); -vers = str2num(vers(1:indp(2)-1)); -if vers < 7.06 - tmpWarning = warning('backtrace'); - warning backtrace off; +end +if ismatlab && vers < 7.06 + tmpWarning = warning('query','backtrace'); + warning off backtrace; warning('You are using a Matlab version older than 7.6 (2008a)'); warning('Some of the EEGLAB functions might not be functional'); warning('Download EEGLAB 4.3b at http://sccn.ucsd.edu/eeglab/eeglab4.5b.teaching.zip'); warning('This version of EEGLAB is compatible with all Matlab version down to Matlab 5.3'); - warning(tmpWarning); -end; + warning( tmpWarning.state, 'backtrace'); +end +if ~ismatlab + warning('off', 'Octave:abbreviated-property-match'); + warning('off', 'Octave:legacy-function'); + warning('off', 'Octave:num-to-str'); + warning('off', 'backtrace'); + warning('off', 'Octave:divide-by-zero'); + try + pkg load statistics + catch + warning('Statistics module not found - type "pkg install -forge io" then "pkg install -forge statistics" to install it'); + end + try + pkg load signal + catch + warning('Signal processing module not found - type "pkg install -forge control" then "pkg install -forge signal" to install it'); + end +end + +% check potential issues with strjoin +% ----------------------------------- +strjoinPath = fileparts(which('strjoin')); +[~,strjoinPath2] = fileparts(strjoinPath); +if ~strcmpi(strjoinPath2, 'strfun') + warning(sprintf('Potential function conflict for strjoin.m located in "%s" \nWe suggest removing the path from MATLAB to avoid problems.', strjoinPath)); +end % check for duplicate versions of EEGLAB % -------------------------------------- eeglabpath = mywhich('eeglab.m'); eeglabpath = eeglabpath(1:end-length('eeglab.m')); -if nargin < 1 +if nargin < 1 && ~isdeployed eeglabpath2 = ''; if strcmpi(eeglabpath, pwd) || strcmpi(eeglabpath(1:end-1), pwd) cd('functions'); @@ -194,26 +252,25 @@ eeglabpath2 = mywhich('eeglab.m'); cd('..'); else - try, rmpath(eeglabpath); catch, end; + try, rmpath(eeglabpath); catch, end eeglabpath2 = mywhich('eeglab.m'); - end; + end if ~isempty(eeglabpath2) - %evalin('base', 'clear classes updater;'); % this clears all the variables eeglabpath2 = eeglabpath2(1:end-length('eeglab.m')); - tmpWarning = warning('backtrace'); - warning backtrace off; + tmpWarning = warning('query', 'backtrace'); + warning off backtrace; disp('******************************************************'); warning('There are at least two versions of EEGLAB in your path'); warning(sprintf('One is at %s', eeglabpath)); warning(sprintf('The other one is at %s', eeglabpath2)); - warning(tmpWarning); - end; + warning(tmpWarning.state, 'backtrace'); + end addpath(eeglabpath); -end; +end % add the paths % ------------- -if strcmpi(eeglabpath, './') || strcmpi(eeglabpath, '.\'), eeglabpath = [ pwd filesep ]; end; +if strcmpi(eeglabpath, './') || strcmpi(eeglabpath, '.\'), eeglabpath = [ pwd filesep ]; end % solve BIOSIG problem % -------------------- @@ -221,51 +278,52 @@ if ~isempty(pathtmp) try, rmpath(pathtmp(1:end-15)); - catch, end; -end; + catch, end +end % test for local SCCN copy % ------------------------ -if ~iseeglabdeployed2 +if ~isdeployed addpathifnotinlist(eeglabpath); if exist( fullfile( eeglabpath, 'functions', 'adminfunc') ) ~= 7 warning('EEGLAB subfolders not found'); - end; -end; + end +end % determine file format % --------------------- fileformat = 'maclinux'; comp = computer; try - if strcmpi(comp(1:3), 'GLN') | strcmpi(comp(1:3), 'MAC') | strcmpi(comp(1:3), 'SOL') + if strcmpi(comp(1:3), 'GLN') || strcmpi(comp(1:3), 'MAC') || strcmpi(comp(1:3), 'SOL') fileformat = 'maclinux'; elseif strcmpi(comp(1:5), 'pcwin') fileformat = 'pcwin'; - end; -end; + end +end % add paths % --------- -if ~iseeglabdeployed2 +if ~isdeployed tmp = which('eeglab_data.set'); - if ~isempty(which('eeglab_data.set')) && ~isempty(which('GSN-HydroCel-32.sfp')) - warning backtrace off; + if ~isempty(which('eeglab_data.set')) && ~isempty(which('Standard-10-10-Cap47.ced')) + tmpWarning = warning('query', 'backtrace'); + warning off backtrace; warning(sprintf([ '\n\nPath Warning: It appears that you have added the path to all of the\n' ... 'subfolders to EEGLAB. This may create issues with some EEGLAB extensions\n' ... 'If EEGLAB cannot start or your experience a large number of warning\n' ... 'messages, remove all the EEGLAB paths then go to the EEGLAB folder\n' ... 'and start EEGLAB which will add all the necessary paths.\n\n' ])); - warning backtrace on; + warning(tmpWarning.state, 'backtrace'); foldertorm = fileparts(which('fgetl.m')); if ~isempty(strfind(foldertorm, 'eeglab')) rmpath(foldertorm); - end; + end foldertorm = fileparts(which('strjoin.m')); if ~isempty(strfind(foldertorm, 'eeglab')) rmpath(foldertorm); - end; - end; + end + end myaddpath( eeglabpath, 'eeg_checkset.m', [ 'functions' filesep 'adminfunc' ]); myaddpath( eeglabpath, 'eeg_checkset.m', [ 'functions' filesep 'adminfunc' ]); myaddpath( eeglabpath, ['@mmo' filesep 'mmo.m'], 'functions'); @@ -276,8 +334,7 @@ myaddpath( eeglabpath, 'statcond.m', [ 'functions' filesep 'statistics' ]); myaddpath( eeglabpath, 'timefreq.m', [ 'functions' filesep 'timefreqfunc' ]); myaddpath( eeglabpath, 'icademo.m', [ 'functions' filesep 'miscfunc' ]); - myaddpath( eeglabpath, 'eeglab1020.ced', [ 'functions' filesep 'resources' ]); - myaddpath( eeglabpath, 'startpane.m', [ 'functions' filesep 'javachatfunc' ]); + myaddpath( eeglabpath, 'eeglab1020.ced', [ 'functions' filesep 'supportfiles' ]); addpathifnotinlist(fullfile(eeglabpath, 'plugins')); eeglab_options; @@ -285,57 +342,49 @@ path_runica = fileparts(mywhich('runica')); if length(path_runica) > 6 && strcmpi(path_runica(end-5:end), 'fmrlab') rmpath(path_runica); - end; + end % add path if toolboxes are missing % --------------------------------- - signalpath = fullfile(eeglabpath, 'functions', 'octavefunc', 'signal'); - optimpath = fullfile(eeglabpath, 'functions', 'octavefunc', 'optim'); if option_donotusetoolboxes p1 = fileparts(mywhich('ttest')); p2 = fileparts(mywhich('filtfilt')); p3 = fileparts(mywhich('optimtool')); p4 = fileparts(mywhich('gray2ind')); - if ~isempty(p1), rmpath(p1); end; - if ~isempty(p2), rmpath(p2); end; - if ~isempty(p3), rmpath(p3); end; - if ~isempty(p4), rmpath(p4); end; - end; - if ~license('test','signal_toolbox') || exist('pwelch') ~= 2 - warning('off', 'MATLAB:dispatcher:nameConflict'); - addpath( signalpath ); - else - warning('off', 'MATLAB:rmpath:DirNotFound'); - rmpathifpresent( signalpath ); - rmpathifpresent(optimpath); - warning('on', 'MATLAB:rmpath:DirNotFound'); - end; - if ~license('test','optim_toolbox') && ~ismatlab - addpath( optimpath ); - else - warning('off', 'MATLAB:rmpath:DirNotFound'); - rmpathifpresent( optimpath ); - warning('on', 'MATLAB:rmpath:DirNotFound'); - end; + if ~isempty(p1), rmpath(p1); end + if ~isempty(p2), rmpath(p2); end + if ~isempty(p3), rmpath(p3); end + if ~isempty(p4), rmpath(p4); end + end + + % remove BIOSIG path which are not needed and might cause conflicts + biosigp{1} = fileparts(which('sopen.m')); + biosigp{2} = fileparts(which('regress_eog.m')); + biosigp{3} = fileparts(which('DecimalFactors.txt')); + removepath(fileparts(fileparts(biosigp{1})), biosigp{:}) else eeglab_options; -end; +end -if nargin == 1 && strcmp(onearg, 'redraw') - if evalin('base', 'exist(''EEG'')', '0') == 1 - evalin('base', 'eeg_global;'); - end; -end; +% declare the variables as global +evalin('base', 'eeg_global;'); eeg_global; % remove empty datasets in ALLEEG while ~isempty(ALLEEG) && isempty(ALLEEG(end).data) ALLEEG(end) = []; -end; +end +if isempty(CURRENTSET) + if isequal(CURRENTSTUDY, 0) + CURRENTSET = 1; + else + CURRENTSET = 1:length(ALLEEG); + end +end if ~isempty(ALLEEG) && max(CURRENTSET) > length(ALLEEG) CURRENTSET = 1; EEG = eeg_retrieve(ALLEEG, CURRENTSET); -end; +end % for the history function % ------------------------ @@ -344,55 +393,75 @@ evalin('caller', comtmp, ''); evalin('base', 'eeg_global;'); -if nargin < 1 | exist('EEG') ~= 1 - clear global EEG ALLEEG CURRENTSET ALLCOM LASTCOM STUDY; +if nargin < 1 || exist('EEG') ~= 1 + EEG = []; + ALLEEG = []; + CURRENTSET = []; + ALLCOM = []; + LASTCOM = []; + STUDY =[]; CURRENTSTUDY = 0; - eeg_global; EEG = eeg_emptyset; eegh('[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;'); if ismatlab && get(0, 'screendepth') <= 8 disp('Warning: screen color depth too low, some colors will be inaccurate in time-frequency plots'); - end; -end; + end +end +if isempty(CURRENTSTUDY) CURRENTSTUDY = 0; end +versL = ~option_allmenus; if nargin == 1 if strcmp(onearg, 'versions') disp( [ 'EEGLAB v' eeg_getversion ] ); elseif strcmp(onearg, 'nogui') - if nargout < 1, clear ALLEEG; end; % do not return output var - return; + if nargout < 1, clear ALLEEG; end % do not return output var elseif strcmp(onearg, 'redraw') - if ~ismatlab,return; end; W_MAIN = findobj('tag', 'EEGLAB'); if ~isempty(W_MAIN) updatemenu; - if nargout < 1, clear ALLEEG; end; % do not return output var + if nargout < 1, clear ALLEEG; end % do not return output var return; else eegh('eeglab(''redraw'');'); - end; - elseif strcmp(onearg, 'rebuild') - if ~ismatlab,return; end; + end + elseif strcmpi(onearg, 'continuous') || strcmpi(onearg, 'cont') + ALLEEG = []; CURRENTSET = 0; CURRENTSTUDY = 0; STUDY = []; + disp('Clearing all data and loading tutorial continuous data') + EEG = pop_loadset(fullfile(eeglabpath, 'sample_data', 'eeglab_data.set')); + eeglab redraw; + return + elseif strcmp(onearg, 'epoch') + ALLEEG = []; CURRENTSET = 0; CURRENTSTUDY = 0; STUDY = []; + disp('Clearing all data and loading tutorial epoched data') + EEG = pop_loadset(fullfile(eeglabpath, 'sample_data', 'eeglab_data_epochs_ica.set')); + eeglab redraw; + return + elseif strcmp(onearg, 'rebuild') W_MAIN = findobj('tag', 'EEGLAB'); close(W_MAIN); - eeglab; + eeglab redraw; return; + elseif strcmp(onearg, 'full') + versL = false; else fprintf(2,['EEGLAB Warning: Invalid argument ''' onearg '''. Restarting EEGLAB interface instead.\n']); eegh('[ALLEEG EEG CURRENTSET ALLCOM] = eeglab(''rebuild'');'); - end; + end else onearg = 'rebuild'; -end; +end ALLCOM = ALLCOM; -try, eval('colordef white;'); catch end; +try, colordef('white'); catch end +if versL + disp('Some menus items hidden. Use Preference menu to show them all.'); +end % default option folder % --------------------- -if ~iseeglabdeployed2 +if ~isdeployed eeglab_options; fprintf('eeglab: options file is %s%seeg_options.m\n', homefolder, filesep); -end; +end % checking strings % ---------------- @@ -419,32 +488,29 @@ ' eegh(''[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET, ''''savedata'''');'');' ... 'end;' ]; -storecall = '[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); eegh(''[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);'');'; -storenewcall = '[ALLEEG EEG CURRENTSET LASTCOM] = pop_newset(ALLEEG, EEG, CURRENTSET, ''study'', ~isempty(STUDY)+0); eegh(LASTCOM);'; -storeallcall = [ 'if ~isempty(ALLEEG) & ~isempty(ALLEEG(1).data), ALLEEG = eeg_checkset(ALLEEG);' ... - 'EEG = eeg_retrieve(ALLEEG, CURRENTSET); eegh(''ALLEEG = eeg_checkset(ALLEEG); EEG = eeg_retrieve(ALLEEG, CURRENTSET);''); end;' ]; - +storenewcall = 'EEG = eegh(LASTCOM, EEG); [ALLEEG EEG CURRENTSET LASTCOM] = pop_newset(ALLEEG, EEG, CURRENTSET, ''study'', ~isempty(STUDY)+0); eegh(LASTCOM);'; +storecall = 'EEG = eegh(LASTCOM, EEG); [ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); eegh(''[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);'');'; +storecall = 'EEG = eegh(LASTCOM, EEG); [ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);'; testeegtmp = 'if exist(''EEGTMP'') == 1, EEG = EEGTMP; clear EEGTMP; end;'; % for backward compatibility -ifeeg = 'if ~isempty(LASTCOM) & ~isempty(EEG),'; -ifeegnh = 'if ~isempty(LASTCOM) & ~isempty(EEG) & ~isempty(findstr(''='',LASTCOM)),'; +ifeeg = 'if ~isempty(LASTCOM) && ~isempty(EEG),'; % nh = no dataset history % ----------------------- -e_storeall_nh = [e_catch 'eegh(LASTCOM);' ifeeg storeallcall 'disp(''Done.''); end; eeglab(''redraw'');']; -e_hist_nh = [e_catch 'eegh(LASTCOM);']; - -% same as above but also save history in dataset -% ---------------------------------------------- -e_newset = [e_catch 'EEG = eegh(LASTCOM, EEG);' testeegtmp ifeeg storenewcall 'disp(''Done.''); end; eeglab(''redraw'');']; -e_store = [e_catch 'EEG = eegh(LASTCOM, EEG);' ifeegnh storecall 'disp(''Done.''); end; eeglab(''redraw'');']; -e_hist = [e_catch 'EEG = eegh(LASTCOM, EEG);']; -e_histdone = [e_catch 'EEG = eegh(LASTCOM, EEG); if ~isempty(LASTCOM), disp(''Done.''); end;' ]; +e_hist_noeegh = [e_catch 'eegh(LASTCOM);']; % study checking % -------------- +e_check_study = 'if length(EEG) > 1 && CURRENTSTUDY == 1, STUDY = std_checkset(STUDY, ALLEEG); eegh(''STUDY = std_checkset(STUDY, ALLEEG);''); end;'; e_load_study = [e_catch 'if ~isempty(LASTCOM), STUDY = STUDYTMP; STUDY = eegh(LASTCOM, STUDY); ALLEEG = ALLEEGTMP; EEG = ALLEEG; CURRENTSET = [1:length(EEG)]; eegh(''CURRENTSTUDY = 1; EEG = ALLEEG; CURRENTSET = [1:length(EEG)];''); CURRENTSTUDY = 1; disp(''Done.''); end; clear ALLEEGTMP STUDYTMP; eeglab(''redraw'');']; e_plot_study = [e_catch 'if ~isempty(LASTCOM), STUDY = STUDYTMP; STUDY = eegh(LASTCOM, STUDY); disp(''Done.''); end; clear ALLEEGTMP STUDYTMP; eeglab(''redraw'');']; % ALLEEG not modified +% same as above but also save history in dataset +% ---------------------------------------------- +e_newset = [e_catch testeegtmp 'eeglab_new;' e_check_study ]; +e_store = [e_catch 'eeglab_new;' ]; +e_hist = [e_catch 'eeglab_new;' ]; +e_histdone = [e_catch 'eeglab_new; disp(''done'');' ]; + % build structures for plugins % ---------------------------- trystrs.no_check = e_try; @@ -457,54 +523,51 @@ trystrs.check_chanlocs = checkplot; trystrs.check_epoch_chanlocs = checkepochplot; trystrs.check_epoch_ica_chanlocs = checkepochicaplot; -catchstrs.add_to_hist = e_hist; +trystrs.check_ica_chanlocs = checkicaplot; +catchstrs.add_to_hist = e_store; catchstrs.store_and_hist = e_store; catchstrs.new_and_hist = e_newset; catchstrs.new_non_empty = e_newset; catchstrs.update_study = e_plot_study; +catchstrs.load_study = e_load_study; % create eeglab figure % -------------------- -javaobj = eeg_mainfig(onearg); +if ~strcmpi(onearg, 'nogui') + eeg_mainfig(onearg); +end % detecting icalab % ---------------- if exist('icalab') disp('ICALAB toolbox detected (algo. added to "run ICA" interface)'); -end; +end -if ~iseeglabdeployed2 +if ~isdeployed % check for older version of Fieldtrip and presence of topoplot % ------------------------------------------------------------- - if ismatlab - ptopoplot = fileparts(mywhich('cbar')); - ptopoplot2 = fileparts(mywhich('topoplot')); - if ~strcmpi(ptopoplot, ptopoplot2), - %disp(' Warning: duplicate function topoplot.m in Fieldtrip and EEGLAB'); - %disp(' EEGLAB function will prevail and call the Fieldtrip one when appropriate'); - addpath(ptopoplot); - end; - end; -end; + ptopoplot = fileparts(mywhich('cbar')); + ptopoplot2 = fileparts(mywhich('topoplot')); + if ~strcmpi(ptopoplot, ptopoplot2), + %disp(' Warning: duplicate function topoplot.m in Fieldtrip and EEGLAB'); + %disp(' EEGLAB function will prevail and call the Fieldtrip one when appropriate'); + addpath(ptopoplot); + end + pcheck = fileparts(mywhich('finputcheck')); + if ~strfind(pcheck, 'guifunc') + rmpath(fileparts(pcheck)); + end +end cb_importdata = [ nocheck '[EEG LASTCOM] = pop_importdata;' e_newset ]; -cb_readegi = [ nocheck '[EEG LASTCOM] = pop_readegi;' e_newset ]; -cb_readsegegi = [ nocheck '[EEG LASTCOM] = pop_readsegegi;' e_newset ]; -cb_readegiepo = [ nocheck '[EEG LASTCOM] = pop_importegimat;' e_newset ]; -cb_loadbci = [ nocheck '[EEG LASTCOM] = pop_loadbci;' e_newset ]; -cb_snapread = [ nocheck '[EEG LASTCOM] = pop_snapread;' e_newset ]; -cb_loadcnt = [ nocheck '[EEG LASTCOM] = pop_loadcnt;' e_newset ]; -cb_loadeeg = [ nocheck '[EEG LASTCOM] = pop_loadeeg;' e_newset ]; cb_biosig = [ nocheck '[EEG LASTCOM] = pop_biosig; ' e_newset ]; cb_fileio = [ nocheck '[EEG LASTCOM] = pop_fileio; ' e_newset ]; -cb_fileio2 = [ nocheck '[EEG LASTCOM] = pop_fileiodir;' e_newset ]; cb_importepoch = [ checkepoch '[EEG LASTCOM] = pop_importepoch(EEG);' e_store ]; -cb_loaddat = [ checkepoch '[EEG LASTCOM]= pop_loaddat(EEG);' e_store ]; cb_importevent = [ check '[EEG LASTCOM] = pop_importevent(EEG);' e_store ]; cb_chanevent = [ check '[EEG LASTCOM]= pop_chanevent(EEG);' e_store ]; cb_importpres = [ check '[EEG LASTCOM]= pop_importpres(EEG);' e_store ]; -cb_importev2 = [ check '[EEG LASTCOM]= pop_importev2(EEG);' e_store ]; +cb_importerplab= [ check '[EEG LASTCOM]= pop_importerplab(EEG);' e_store ]; cb_export = [ check 'LASTCOM = pop_export(EEG);' e_histdone ]; cb_expica1 = [ check 'LASTCOM = pop_expica(EEG, ''weights'');' e_histdone ]; cb_expica2 = [ check 'LASTCOM = pop_expica(EEG, ''inv'');' e_histdone ]; @@ -514,21 +577,20 @@ cb_loadset = [ nocheck '[EEG LASTCOM] = pop_loadset;' e_newset]; cb_saveset = [ check '[EEG LASTCOM] = pop_saveset(EEG, ''savemode'', ''resave'');' e_store ]; cb_savesetas = [ check '[EEG LASTCOM] = pop_saveset(EEG);' e_store ]; -cb_delset = [ nocheck '[ALLEEG LASTCOM] = pop_delset(ALLEEG, -CURRENTSET);' e_hist_nh 'eeglab redraw;' ]; +cb_delset = [ nocheck '[ALLEEG LASTCOM] = pop_delset(ALLEEG, -CURRENTSET);' e_hist_noeegh 'eeglab redraw;' ]; cb_study1 = [ nocheck 'pop_stdwarn; [STUDYTMP ALLEEGTMP LASTCOM] = pop_study([], ALLEEG , ''gui'', ''on'');' e_load_study]; cb_study2 = [ nocheck 'pop_stdwarn; [STUDYTMP ALLEEGTMP LASTCOM] = pop_study([], isempty(ALLEEG), ''gui'', ''on'');' e_load_study]; cb_studyerp = [ nocheck 'pop_stdwarn; [STUDYTMP ALLEEGTMP LASTCOM] = pop_studyerp;' e_load_study]; cb_loadstudy = [ nocheck 'pop_stdwarn; [STUDYTMP ALLEEGTMP LASTCOM] = pop_loadstudy; if ~isempty(LASTCOM), STUDYTMP = std_renamestudyfiles(STUDYTMP, ALLEEGTMP); end;' e_load_study]; -cb_savestudy1 = [ check '[STUDYTMP ALLEEGTMP LASTCOM] = pop_savestudy(STUDY, EEG, ''savemode'', ''resave'');' e_load_study]; +cb_savestudy1 = [ check '[STUDYTMP ALLEEGTMP LASTCOM] = pop_savestudy(STUDY, EEG, ''savemode'', ''resavegui'');' e_load_study]; cb_savestudy2 = [ check '[STUDYTMP ALLEEGTMP LASTCOM] = pop_savestudy(STUDY, EEG);' e_load_study]; cb_clearstudy = 'LASTCOM = ''STUDY = []; CURRENTSTUDY = 0; ALLEEG = []; EEG=[]; CURRENTSET=[];''; eval(LASTCOM); eegh( LASTCOM ); eeglab redraw;'; cb_editoptions = [ nocheck 'if isfield(ALLEEG, ''nbchan''), LASTCOM = pop_editoptions(length([ ALLEEG.nbchan ]) >1);' ... - 'else LASTCOM = pop_editoptions(0); end;' e_storeall_nh]; -cb_plugin1 = [ nocheck 'if plugin_extract(''import'', PLUGINLIST) , close(findobj(''tag'', ''EEGLAB'')); eeglab redraw; end;' e_hist_nh ]; -cb_plugin2 = [ nocheck 'if plugin_extract(''process'', PLUGINLIST), close(findobj(''tag'', ''EEGLAB'')); eeglab redraw; end;' e_hist_nh ]; + 'else LASTCOM = pop_editoptions(0); end;' e_hist_noeegh ]; +cb_plugin = [ nocheck 'if plugin_menu(PLUGINLIST) , close(findobj(''tag'', ''EEGLAB'')); eeglab redraw; end;' e_hist_noeegh ]; -cb_saveh1 = [ nocheck 'LASTCOM = pop_saveh(EEG.history);' e_hist_nh]; -cb_saveh2 = [ nocheck 'LASTCOM = pop_saveh(ALLCOM);' e_hist_nh]; +cb_saveh1 = [ nocheck 'LASTCOM = pop_saveh(EEG.history);' e_hist_noeegh]; +cb_saveh2 = [ nocheck 'LASTCOM = pop_saveh(ALLCOM);' e_hist_noeegh]; cb_runsc = [ nocheck 'LASTCOM = pop_runscript;' e_hist ]; cb_quit = [ 'close(gcf); disp(''To save the EEGLAB command history >> pop_saveh(ALLCOM);'');' ... 'clear global EEG ALLEEG LASTCOM CURRENTSET;']; @@ -536,40 +598,42 @@ cb_editset = [ check '[EEG LASTCOM] = pop_editset(EEG);' e_store]; cb_editeventf = [ checkevent '[EEG LASTCOM] = pop_editeventfield(EEG);' e_store]; cb_editeventv = [ checkevent '[EEG LASTCOM] = pop_editeventvals(EEG);' e_store]; -cb_comments = [ check '[EEG.comments LASTCOM] =pop_comments(EEG.comments, ''About this dataset'');' e_store]; -cb_chanedit = [ 'disp(''IMPORTANT: After importing/modifying data channels, you must close'');' ... +cb_adjustevents= [ checkevent '[EEG LASTCOM] = pop_adjustevents(EEG);' e_store]; +cb_comments = [ check '[EEG LASTCOM] =pop_comments(EEG, ''About this dataset'');' e_store]; +cb_chanedit = [ check 'disp(''IMPORTANT: After importing/modifying data channels, you must close'');' ... 'disp(''the channel editing window for the changes to take effect in EEGLAB.'');' ... - 'disp(''TIP: Call this function directy from the prompt, ">> pop_chanedit([]);"'');' ... + 'disp(''TIP: Call this function directly from the prompt, ">> pop_chanedit([]);"'');' ... 'disp('' to convert between channel location file formats'');' ... - '[EEG TMPINFO TMP LASTCOM] = pop_chanedit(EEG); if ~isempty(LASTCOM), EEG = eeg_checkset(EEG, ''chanlocsize'');' ... - 'clear TMPINFO TMP; EEG = eegh(LASTCOM, EEG);' storecall 'end; eeglab(''redraw'');']; + '[EEG TMPINFO TMP LASTCOM] = pop_chanedit(EEG); clear TMPINFO TMP; if ~isempty(LASTCOM), EEG = eeg_checkset(EEG, ''chanlocsize''); end;' ... + e_store ]; + %'clear TMPINFO TMP; EEG = eegh(LASTCOM, EEG);' storecall 'end; eeglab(''redraw'');']; cb_select = [ check '[EEG LASTCOM] = pop_select(EEG);' e_newset]; cb_rmdat = [ checkevent '[EEG LASTCOM] = pop_rmdat(EEG);' e_newset]; cb_selectevent = [ checkevent '[EEG TMP LASTCOM] = pop_selectevent(EEG); clear TMP;' e_newset ]; -cb_copyset = [ check '[ALLEEG EEG CURRENTSET LASTCOM] = pop_copyset(ALLEEG, CURRENTSET); eeglab(''redraw'');' e_hist_nh]; +cb_copyset = [ check '[ALLEEG EEG CURRENTSET LASTCOM] = pop_copyset(ALLEEG, CURRENTSET); eeglab(''redraw'');' e_hist_noeegh]; cb_mergeset = [ check '[EEG LASTCOM] = pop_mergeset(ALLEEG);' e_newset]; cb_resample = [ check '[EEG LASTCOM] = pop_resample(EEG);' e_newset]; cb_eegfilt = [ check '[EEG LASTCOM] = pop_eegfilt(EEG);' e_newset]; cb_interp = [ check '[EEG LASTCOM] = pop_interp(EEG); ' e_newset]; cb_reref = [ check '[EEG LASTCOM] = pop_reref(EEG);' e_newset]; -cb_eegplot = [ checkcont '[LASTCOM] = pop_eegplot(EEG, 1);' e_hist]; -cb_epoch = [ check '[EEG tmp LASTCOM] = pop_epoch(EEG); clear tmp;' e_newset check '[EEG LASTCOM] = pop_rmbase(EEG);' e_newset]; -cb_rmbase = [ check '[EEG LASTCOM] = pop_rmbase(EEG);' e_store]; -cb_runica = [ check '[EEG LASTCOM] = pop_runica(EEG);' e_store]; +cb_eegplot = [ check '[LASTCOM] = pop_eegplot(EEG, 1);' e_hist]; +cb_epoch = [ check '[EEG,~,LASTCOM] = pop_epoch(EEG); clear tmp;' e_newset check '[EEG LASTCOM] = pop_rmbase(EEG);' e_newset e_check_study ]; +cb_rmbase = [ check '[EEG LASTCOM] = pop_rmbase(EEG);' e_newset]; +cb_runica = [ check '[EEG LASTCOM] = pop_runica(EEG);' e_store e_check_study]; cb_subcomp = [ checkica '[EEG LASTCOM] = pop_subcomp(EEG);' e_newset]; %cb_chanrej = [ check 'pop_rejchan(EEG); LASTCOM = '''';' e_hist]; -cb_chanrej = [ check '[EEG tmp1 tmp2 LASTCOM] = pop_rejchan(EEG); clear tmp1 tmp2;' e_hist]; -cb_autorej = [ checkepoch '[EEG tmpp LASTCOM] = pop_autorej(EEG); clear tmpp;' e_hist]; -cb_rejcont = [ check '[EEG tmp1 tmp2 LASTCOM] = pop_rejcont(EEG); clear tmp1 tmp2;' e_hist]; +cb_chanrej = [ check '[EEG ~ ~ LASTCOM] = pop_rejchan(EEG);' e_hist]; +cb_autorej = [ checkepoch '[EEG ~ LASTCOM] = pop_autorej(EEG);' e_hist]; +cb_rejcont = [ check '[EEG ~ ~ LASTCOM] = pop_rejcont(EEG);' e_hist]; cb_rejmenu1 = [ check 'pop_rejmenu(EEG, 1); LASTCOM = '''';' e_hist]; cb_eegplotrej1 = [ check '[LASTCOM] = pop_eegplot(EEG, 1);' e_hist]; -cb_eegthresh1 = [ checkepoch '[TMP LASTCOM] = pop_eegthresh(EEG, 1); clear TMP;' e_hist]; +cb_eegthresh1 = [ checkepoch '[~ LASTCOM] = pop_eegthresh(EEG, 1);' e_hist]; cb_rejtrend1 = [ checkepoch '[EEG LASTCOM] = pop_rejtrend(EEG, 1);' e_store]; cb_jointprob1 = [ checkepoch '[EEG LASTCOM] = pop_jointprob(EEG, 1);' e_store]; cb_rejkurt1 = [ checkepoch '[EEG LASTCOM] = pop_rejkurt(EEG, 1);' e_store]; -cb_rejspec1 = [ checkepoch '[EEG Itmp LASTCOM] = pop_rejspec(EEG, 1); clear Itmp;' e_store]; +cb_rejspec1 = [ checkepoch '[EEG ~ LASTCOM] = pop_rejspec(EEG, 1);' e_store]; cb_rejsup1 = [ checkepochica '[EEG LASTCOM] = eeg_rejsuperpose(EEG, 1,1,1,1,1,1,1,1); eegh(LASTCOM);' ... 'LASTCOM = ''EEG.reject.icarejmanual = EEG.reject.rejglobal;''; eval(LASTCOM);' e_store ]; cb_rejsup2 = [ checkepoch '[EEG LASTCOM] = eeg_rejsuperpose(EEG, 1,1,1,1,1,1,1,1); EEG = eegh(LASTCOM, EEG);' ... @@ -608,8 +672,8 @@ cb_headplot2 = [ checkicaplot '[EEG LASTCOM] = pop_headplot(EEG, 0);' e_store]; cb_prop2 = [ checkicaplot 'LASTCOM = pop_prop(EEG,0);' e_hist]; cb_erpimage2 = [ checkepochica 'LASTCOM = pop_erpimage(EEG, 0, eegh(''find'',''pop_erpimage(EEG,0''));' e_hist]; -cb_envtopo1 = [ checkica 'LASTCOM = pop_envtopo(EEG);' e_hist]; -cb_envtopo2 = [ checkica 'if length(ALLEEG) == 1, error(''Need at least 2 datasets''); end; LASTCOM = pop_envtopo(ALLEEG);' e_hist]; +cb_envtopo1 = [ checkicaplot 'LASTCOM = pop_envtopo(EEG);' e_hist]; +cb_envtopo2 = [ checkicaplot 'if length(ALLEEG) == 1, error(''Need at least 2 datasets''); end; LASTCOM = pop_envtopo(ALLEEG);' e_hist]; cb_plotdata2 = [ checkepochica '[tmpeeg LASTCOM] = pop_plotdata(EEG, 0); clear tmpeeg;' e_hist]; cb_comperp2 = [ checkepochica 'LASTCOM = pop_comperp(ALLEEG, 0);' e_hist]; @@ -629,6 +693,7 @@ cb_preclust = [ nocheck '[STUDYTMP ALLEEGTMP LASTCOM] = pop_preclust(STUDY, ALLEEG);' e_plot_study]; cb_clust = [ nocheck '[STUDYTMP ALLEEGTMP LASTCOM] = pop_clust(STUDY, ALLEEG);' e_plot_study]; cb_clustedit = [ nocheck 'ALLEEGTMP = ALLEEG; [STUDYTMP LASTCOM] = pop_clustedit(STUDY, ALLEEG);' e_plot_study]; + % % % add STUDY plugin menus % if exist('eegplugin_stderpimage') @@ -642,403 +707,508 @@ % menu definition % --------------- -if ismatlab - % defaults - % -------- - % startup:on - % study:off - % chanloc:off - % epoch:on - % continuous:on - - on = 'study:on'; - onnostudy = ''; - ondata = 'startup:off'; - onepoch = 'startup:off;continuous:off'; - ondatastudy = 'startup:off;study:on'; - onchannel = 'startup:off;chanloc:on'; - onepochchan = 'startup:off;continuous:off;chanloc:on'; - onstudy = 'startup:off;epoch:off;continuous:off;study:on'; - +% defaults +% -------- +% startup:on +% study:off +% chanloc:off +% epoch:on +% continuous:on + +on = 'study:on'; +onnostudy = ''; +ondata = 'startup:off'; +ondatanoroi = 'startup:off;roi:off'; +onepoch = 'startup:off;continuous:off'; +onepochnoroi = 'startup:off;continuous:off;roi:off'; +ondatastudy = 'startup:off;study:on'; +ondatastudynoroi = 'startup:off;study:on;roi:off'; +onchannel = 'startup:off;chanloc:on'; +onchannelnoroi = 'startup:off;chanloc:on;roi:off'; +onepochchan = 'startup:off;continuous:off;chanloc:on'; +onstudy = 'startup:off;epoch:off;continuous:off;study:on'; +onstudynoroi = 'startup:off;epoch:off;continuous:off;study:on;roi:off'; + +if ~strcmpi(onearg, 'nogui') W_MAIN = findobj('tag', 'EEGLAB'); EEGUSERDAT = get(W_MAIN, 'userdata'); set(W_MAIN, 'MenuBar', 'none'); - file_m = uimenu( W_MAIN, 'Label', 'File' , 'userdata', on); - import_m = uimenu( file_m, 'Label', 'Import data' , 'userdata', onnostudy); - neuro_m = uimenu( import_m, 'Label', 'Using EEGLAB functions and plugins' , 'tag', 'import data' , 'userdata', onnostudy); - epoch_m = uimenu( file_m, 'Label', 'Import epoch info', 'tag', 'import epoch', 'userdata', onepoch); - event_m = uimenu( file_m, 'Label', 'Import event info', 'tag', 'import event', 'userdata', ondata); - exportm = uimenu( file_m, 'Label', 'Export' , 'tag', 'export' , 'userdata', ondata); - edit_m = uimenu( W_MAIN, 'Label', 'Edit' , 'userdata', ondata); - tools_m = uimenu( W_MAIN, 'Label', 'Tools', 'tag', 'tools' , 'userdata', ondatastudy); - plot_m = uimenu( W_MAIN, 'Label', 'Plot', 'tag', 'plot' , 'userdata', ondata); - loc_m = uimenu( plot_m, 'Label', 'Channel locations' , 'userdata', onchannel); - std_m = uimenu( W_MAIN, 'Label', 'Study', 'tag', 'study' , 'userdata', onstudy); - set_m = uimenu( W_MAIN, 'Label', 'Datasets' , 'userdata', ondatastudy); - help_m = uimenu( W_MAIN, 'Label', 'Help' , 'userdata', on); - - uimenu( neuro_m, 'Label', 'From ASCII/float file or Matlab array' , 'CallBack', cb_importdata); - %uimenu( neuro_m, 'Label', 'From Netstation .mff (FILE-IO toolbox)', 'CallBack', cb_fileio2, 'Separator', 'on'); - uimenu( neuro_m, 'Label', 'From Netstation binary simple file' , 'CallBack', cb_readegi, 'Separator', 'on'); - uimenu( neuro_m, 'Label', 'From Multiple seg. Netstation files' , 'CallBack', cb_readsegegi); - uimenu( neuro_m, 'Label', 'From Netstation Matlab files' , 'CallBack', cb_readegiepo); - uimenu( neuro_m, 'Label', 'From BCI2000 ASCII file' , 'CallBack', cb_loadbci, 'Separator', 'on'); - uimenu( neuro_m, 'Label', 'From Snapmaster .SMA file' , 'CallBack', cb_snapread, 'Separator', 'on'); - uimenu( neuro_m, 'Label', 'From Neuroscan .CNT file' , 'CallBack', cb_loadcnt, 'Separator', 'on'); - uimenu( neuro_m, 'Label', 'From Neuroscan .EEG file' , 'CallBack', cb_loadeeg); + file_m = eegmenu( false, W_MAIN, 'Label', 'File' , 'userdata', on); + import_m = eegmenu( false, file_m, 'Label', 'Import data' , 'userdata', onnostudy); + neuro_m = eegmenu( false, import_m, 'Label', 'Using EEGLAB functions and plugins' , 'tag', 'import data' , 'userdata', onnostudy); + epoch_m = eegmenu( false, file_m, 'Label', 'Import epoch info', 'tag', 'import epoch', 'userdata', onepoch); + event_m = eegmenu( false, file_m, 'Label', 'Import event info', 'tag', 'import event', 'userdata', ondata); + exportm = eegmenu( false, file_m, 'Label', 'Export' , 'tag', 'export' , 'userdata', ondata); + edit_m = eegmenu( false, W_MAIN, 'Label', 'Edit' , 'userdata', ondatastudy); + tools_m = eegmenu( false, W_MAIN, 'Label', 'Tools', 'tag', 'tools' , 'userdata', ondatastudy); + plot_m = eegmenu( false, W_MAIN, 'Label', 'Plot', 'tag', 'plot' , 'userdata', ondata); + loc_m = eegmenu( false, plot_m, 'Label', 'Channel locations' , 'userdata', onchannel); + std_m = eegmenu( false, W_MAIN, 'Label', 'Study', 'tag', 'study' , 'userdata', onstudy); + set_m = eegmenu( false, W_MAIN, 'Label', 'Datasets' , 'userdata', ondatastudy); + help_m = eegmenu( false, W_MAIN, 'Label', 'Help' , 'userdata', on); + + eegmenu( false, neuro_m, 'Label', '(for more use menu File > Manage EEGLAB extensions)', 'userdata', 'enable:off'); + eegmenu( false, neuro_m, 'Label', 'From ASCII/float file or MATLAB array' , 'CallBack', cb_importdata, 'separator', 'on'); + %eegmenu( false, neuro_m, 'Label', 'From Netstation .mff (FILE-IO toolbox)', 'CallBack', cb_fileio2, 'Separator', 'on'); % BIOSIG MENUS % ------------ - uimenu( neuro_m, 'Label', 'From Biosemi BDF file (BIOSIG toolbox)', 'CallBack' , cb_biosig, 'Separator', 'on'); - uimenu( neuro_m, 'Label', 'From EDF/EDF+/GDF files (BIOSIG toolbox)', 'CallBack', cb_biosig); - - uimenu( epoch_m, 'Label', 'From Matlab array or ASCII file' , 'CallBack', cb_importepoch); - uimenu( epoch_m, 'Label', 'From Neuroscan .DAT file' , 'CallBack', cb_loaddat); - uimenu( event_m, 'Label', 'From Matlab array or ASCII file' , 'CallBack', cb_importevent); - uimenu( event_m, 'Label', 'From data channel' , 'CallBack', cb_chanevent); - uimenu( event_m, 'Label', 'From Presentation .LOG file' , 'CallBack', cb_importpres); - uimenu( event_m, 'Label', 'From E-Prime ASCII (text) file' , 'CallBack', cb_importevent); - uimenu( event_m, 'Label', 'From Neuroscan .ev2 file' , 'CallBack', cb_importev2); - uimenu( exportm, 'Label', 'Data and ICA activity to text file' , 'CallBack', cb_export); - uimenu( exportm, 'Label', 'Weight matrix to text file' , 'CallBack', cb_expica1); - uimenu( exportm, 'Label', 'Inverse weight matrix to text file' , 'CallBack', cb_expica2); - uimenu( exportm, 'Label', 'Events to text file' , 'CallBack', cb_expevents); - uimenu( exportm, 'Label', 'Data to EDF/BDF/GDF file' , 'CallBack', cb_expdata, 'separator', 'on'); - - uimenu( file_m, 'Label', 'Load existing dataset' , 'userdata', onnostudy, 'CallBack', cb_loadset, 'Separator', 'on'); - uimenu( file_m, 'Label', 'Save current dataset(s)' , 'userdata', ondatastudy, 'CallBack', cb_saveset); - uimenu( file_m, 'Label', 'Save current dataset as' , 'userdata', ondata, 'CallBack', cb_savesetas); - uimenu( file_m, 'Label', 'Clear dataset(s)' , 'userdata', ondata, 'CallBack', cb_delset); - - std2_m = uimenu( file_m, 'Label', 'Create study' , 'userdata', on , 'Separator', 'on'); - uimenu( std2_m, 'Label', 'Using all loaded datasets' , 'userdata', ondata , 'Callback', cb_study1); - uimenu( std2_m, 'Label', 'Browse for datasets' , 'userdata', on , 'Callback', cb_study2); - uimenu( std2_m, 'Label', 'Simple ERP STUDY' , 'userdata', on , 'Callback', cb_studyerp); - - uimenu( file_m, 'Label', 'Load existing study' , 'userdata', on , 'CallBack', cb_loadstudy,'Separator', 'on' ); - uimenu( file_m, 'Label', 'Save current study' , 'userdata', onstudy, 'CallBack', cb_savestudy1); - uimenu( file_m, 'Label', 'Save current study as' , 'userdata', onstudy, 'CallBack', cb_savestudy2); - uimenu( file_m, 'Label', 'Clear study / Clear all' , 'userdata', ondatastudy, 'CallBack', cb_clearstudy); - uimenu( file_m, 'Label', 'Memory and other options' , 'userdata', on , 'CallBack', cb_editoptions, 'Separator', 'on'); - - hist_m = uimenu( file_m, 'Label', 'History scripts' , 'userdata', on , 'Separator', 'on'); - uimenu( hist_m, 'Label', 'Save dataset history script' , 'userdata', ondata , 'CallBack', cb_saveh1); - uimenu( hist_m, 'Label', 'Save session history script' , 'userdata', ondatastudy, 'CallBack', cb_saveh2); - uimenu( hist_m, 'Label', 'Run script' , 'userdata', on , 'CallBack', cb_runsc); - - plugin_m = uimenu( file_m, 'Label', 'Manage EEGLAB extensions' , 'userdata', on); - uimenu( plugin_m, 'Label', 'Data import extensions' , 'userdata', on , 'CallBack', cb_plugin1); - uimenu( plugin_m, 'Label', 'Data processing extensions' , 'userdata', on , 'CallBack', cb_plugin2); - - uimenu( file_m, 'Label', 'Quit' , 'userdata', on , 'CallBack', cb_quit, 'Separator', 'on'); - - uimenu( edit_m, 'Label', 'Dataset info' , 'userdata', ondata, 'CallBack', cb_editset); - uimenu( edit_m, 'Label', 'Event fields' , 'userdata', ondata, 'CallBack', cb_editeventf); - uimenu( edit_m, 'Label', 'Event values' , 'userdata', ondata, 'CallBack', cb_editeventv); - uimenu( edit_m, 'Label', 'About this dataset' , 'userdata', ondata, 'CallBack', cb_comments); - uimenu( edit_m, 'Label', 'Channel locations' , 'userdata', ondata, 'CallBack', cb_chanedit); - uimenu( edit_m, 'Label', 'Select data' , 'userdata', ondata, 'CallBack', cb_select, 'Separator', 'on'); - uimenu( edit_m, 'Label', 'Select data using events' , 'userdata', ondata, 'CallBack', cb_rmdat); - uimenu( edit_m, 'Label', 'Select epochs or events' , 'userdata', ondata, 'CallBack', cb_selectevent); - uimenu( edit_m, 'Label', 'Copy current dataset' , 'userdata', ondata, 'CallBack', cb_copyset, 'Separator', 'on'); - uimenu( edit_m, 'Label', 'Append datasets' , 'userdata', ondata, 'CallBack', cb_mergeset); - uimenu( edit_m, 'Label', 'Delete dataset(s) from memory' , 'userdata', ondata, 'CallBack', cb_delset); - - uimenu( tools_m, 'Label', 'Change sampling rate' , 'userdata', ondatastudy, 'CallBack', cb_resample); - - filter_m = uimenu( tools_m, 'Label', 'Filter the data' , 'userdata', ondatastudy, 'tag', 'filter'); - uimenu( filter_m, 'Label', 'Basic FIR filter (legacy)' , 'userdata', ondatastudy, 'CallBack', cb_eegfilt); - - uimenu( tools_m, 'Label', 'Re-reference' , 'userdata', ondata, 'CallBack', cb_reref); - uimenu( tools_m, 'Label', 'Interpolate electrodes' , 'userdata', ondata, 'CallBack', cb_interp); - uimenu( tools_m, 'Label', 'Reject continuous data by eye' , 'userdata', ondata, 'CallBack', cb_eegplot); - uimenu( tools_m, 'Label', 'Extract epochs' , 'userdata', ondata, 'CallBack', cb_epoch, 'Separator', 'on'); - uimenu( tools_m, 'Label', 'Remove baseline' , 'userdata', ondatastudy, 'CallBack', cb_rmbase); - uimenu( tools_m, 'Label', 'Run ICA' , 'userdata', ondatastudy, 'CallBack', cb_runica, 'foregroundcolor', 'b', 'Separator', 'on'); - uimenu( tools_m, 'Label', 'Remove components' , 'userdata', ondata, 'CallBack', cb_subcomp); - uimenu( tools_m, 'Label', 'Automatic channel rejection' , 'userdata', ondata, 'CallBack', cb_chanrej, 'Separator', 'on'); - uimenu( tools_m, 'Label', 'Automatic continuous rejection' , 'userdata', ondata, 'CallBack', cb_rejcont); - uimenu( tools_m, 'Label', 'Automatic epoch rejection' , 'userdata', onepoch, 'CallBack', cb_autorej); - rej_m1 = uimenu( tools_m, 'Label', 'Reject data epochs' , 'userdata', onepoch); - rej_m2 = uimenu( tools_m, 'Label', 'Reject data using ICA' , 'userdata', ondata ); - - uimenu( rej_m1, 'Label', 'Reject data (all methods)' , 'userdata', onepoch, 'CallBack', cb_rejmenu1); - uimenu( rej_m1, 'Label', 'Reject by inspection' , 'userdata', onepoch, 'CallBack', cb_eegplotrej1); - uimenu( rej_m1, 'Label', 'Reject extreme values' , 'userdata', onepoch, 'CallBack', cb_eegthresh1); - uimenu( rej_m1, 'Label', 'Reject by linear trend/variance' , 'userdata', onepoch, 'CallBack', cb_rejtrend1); - uimenu( rej_m1, 'Label', 'Reject by probability' , 'userdata', onepoch, 'CallBack', cb_jointprob1); - uimenu( rej_m1, 'Label', 'Reject by kurtosis' , 'userdata', onepoch, 'CallBack', cb_rejkurt1); - uimenu( rej_m1, 'Label', 'Reject by spectra' , 'userdata', onepoch, 'CallBack', cb_rejspec1); - uimenu( rej_m1, 'Label', 'Export marks to ICA reject' , 'userdata', onepoch, 'CallBack', cb_rejsup1, 'separator', 'on'); - uimenu( rej_m1, 'Label', 'Reject marked epochs' , 'userdata', onepoch, 'CallBack', cb_rejsup2, 'separator', 'on', 'foregroundcolor', 'b'); - uimenu( rej_m2, 'Label', 'Reject components by map' , 'userdata', ondata , 'CallBack', cb_selectcomps); - uimenu( rej_m2, 'Label', 'Reject data (all methods)' , 'userdata', onepoch, 'CallBack', cb_rejmenu2, 'Separator', 'on'); - uimenu( rej_m2, 'Label', 'Reject by inspection' , 'userdata', onepoch, 'CallBack', cb_eegplotrej2); - uimenu( rej_m2, 'Label', 'Reject extreme values' , 'userdata', onepoch, 'CallBack', cb_eegthresh2); - uimenu( rej_m2, 'Label', 'Reject by linear trend/variance' , 'userdata', onepoch, 'CallBack', cb_rejtrend2); - uimenu( rej_m2, 'Label', 'Reject by probability' , 'userdata', onepoch, 'CallBack', cb_jointprob2); - uimenu( rej_m2, 'Label', 'Reject by kurtosis' , 'userdata', onepoch, 'CallBack', cb_rejkurt2); - uimenu( rej_m2, 'Label', 'Reject by spectra' , 'userdata', onepoch, 'CallBack', cb_rejspec2); - uimenu( rej_m2, 'Label', 'Export marks to data reject' , 'userdata', onepoch, 'CallBack', cb_rejsup3, 'separator', 'on'); - uimenu( rej_m2, 'Label', 'Reject marked epochs' , 'userdata', onepoch, 'CallBack', cb_rejsup4, 'separator', 'on', 'foregroundcolor', 'b'); - - uimenu( loc_m, 'Label', 'By name' , 'userdata', onchannel, 'CallBack', cb_topoblank1); - uimenu( loc_m, 'Label', 'By number' , 'userdata', onchannel, 'CallBack', cb_topoblank2); - uimenu( plot_m, 'Label', 'Channel data (scroll)' , 'userdata', ondata , 'CallBack', cb_eegplot1, 'Separator', 'on'); - uimenu( plot_m, 'Label', 'Channel spectra and maps' , 'userdata', ondata , 'CallBack', cb_spectopo1); - uimenu( plot_m, 'Label', 'Channel properties' , 'userdata', ondata , 'CallBack', cb_prop1); - uimenu( plot_m, 'Label', 'Channel ERP image' , 'userdata', onepoch, 'CallBack', cb_erpimage1); - - ERP_m = uimenu( plot_m, 'Label', 'Channel ERPs' , 'userdata', onepoch); - uimenu( ERP_m, 'Label', 'With scalp maps' , 'CallBack', cb_timtopo); - uimenu( ERP_m, 'Label', 'In scalp/rect. array' , 'CallBack', cb_plottopo); - - topo_m = uimenu( plot_m, 'Label', 'ERP map series' , 'userdata', onepochchan); - uimenu( topo_m, 'Label', 'In 2-D' , 'CallBack', cb_topoplot1); - uimenu( topo_m, 'Label', 'In 3-D' , 'CallBack', cb_headplot1); - uimenu( plot_m, 'Label', 'Sum/Compare ERPs' , 'userdata', onepoch, 'CallBack', cb_comperp1); - - uimenu( plot_m, 'Label', 'Component activations (scroll)' , 'userdata', ondata , 'CallBack', cb_eegplot2,'Separator', 'on'); - uimenu( plot_m, 'Label', 'Component spectra and maps' , 'userdata', ondata , 'CallBack', cb_spectopo2); - - tica_m = uimenu( plot_m, 'Label', 'Component maps' , 'userdata', onchannel); - uimenu( tica_m, 'Label', 'In 2-D' , 'CallBack', cb_topoplot2); - uimenu( tica_m, 'Label', 'In 3-D' , 'CallBack', cb_headplot2); - uimenu( plot_m, 'Label', 'Component properties' , 'userdata', ondata , 'CallBack', cb_prop2); - uimenu( plot_m, 'Label', 'Component ERP image' , 'userdata', onepoch, 'CallBack', cb_erpimage2); - - ERPC_m = uimenu( plot_m, 'Label', 'Component ERPs' , 'userdata', onepoch); - uimenu( ERPC_m, 'Label', 'With component maps' , 'CallBack', cb_envtopo1); - uimenu( ERPC_m, 'Label', 'With comp. maps (compare)' , 'CallBack', cb_envtopo2); - uimenu( ERPC_m, 'Label', 'In rectangular array' , 'CallBack', cb_plotdata2); - uimenu( plot_m, 'Label', 'Sum/Compare comp. ERPs' , 'userdata', onepoch, 'CallBack', cb_comperp2); - - stat_m = uimenu( plot_m, 'Label', 'Data statistics', 'Separator', 'on', 'userdata', ondata ); - uimenu( stat_m, 'Label', 'Channel statistics' , 'CallBack', cb_signalstat1); - uimenu( stat_m, 'Label', 'Component statistics' , 'CallBack', cb_signalstat2); - uimenu( stat_m, 'Label', 'Event statistics' , 'CallBack', cb_eventstat); - - spec_m = uimenu( plot_m, 'Label', 'Time-frequency transforms', 'Separator', 'on', 'userdata', ondata); - uimenu( spec_m, 'Label', 'Channel time-frequency' , 'CallBack', cb_timef1); - uimenu( spec_m, 'Label', 'Channel cross-coherence' , 'CallBack', cb_crossf1); - uimenu( spec_m, 'Label', 'Component time-frequency' , 'CallBack', cb_timef2,'Separator', 'on'); - uimenu( spec_m, 'Label', 'Component cross-coherence' , 'CallBack', cb_crossf2); - - uimenu( std_m, 'Label', 'Edit study info' , 'userdata', onstudy, 'CallBack', cb_study3); - uimenu( std_m, 'Label', 'Select/Edit study design(s)' , 'userdata', onstudy, 'CallBack', cb_studydesign); - uimenu( std_m, 'Label', 'Precompute channel measures' , 'userdata', onstudy, 'CallBack', cb_precomp, 'separator', 'on'); - uimenu( std_m, 'Label', 'Plot channel measures' , 'userdata', onstudy, 'CallBack', cb_chanplot); - uimenu( std_m, 'Label', 'Precompute component measures' , 'userdata', onstudy, 'CallBack', cb_precomp2, 'separator', 'on'); - clust_m = uimenu( std_m, 'Label', 'PCA clustering (original)' , 'userdata', onstudy); - uimenu( clust_m, 'Label', 'Build preclustering array' , 'userdata', onstudy, 'CallBack', cb_preclust); - uimenu( clust_m, 'Label', 'Cluster components' , 'userdata', onstudy, 'CallBack', cb_clust); - uimenu( std_m, 'Label', 'Edit/plot clusters' , 'userdata', onstudy, 'CallBack', cb_clustedit); - - if ~iseeglabdeployed2 - %newerVersionMenu = uimenu( help_m, 'Label', 'Upgrade to the Latest Version' , 'userdata', on, 'ForegroundColor', [0.6 0 0]); - uimenu( help_m, 'Label', 'About EEGLAB' , 'userdata', on, 'CallBack', 'pophelp(''eeglab'');'); - uimenu( help_m, 'Label', 'About EEGLAB help' , 'userdata', on, 'CallBack', 'pophelp(''eeg_helphelp'');'); - uimenu( help_m, 'Label', 'EEGLAB menus' , 'userdata', on, 'CallBack', 'pophelp(''eeg_helpmenu'');','separator','on'); - - help_1 = uimenu( help_m, 'Label', 'EEGLAB functions', 'userdata', on); - uimenu( help_1, 'Label', 'Admin. functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpadmin'');'); - uimenu( help_1, 'Label', 'Interactive pop_ functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helppop'');'); - uimenu( help_1, 'Label', 'Signal processing functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpsigproc'');'); - uimenu( help_1, 'Label', 'Group data (STUDY) functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpstudy'');'); - uimenu( help_1, 'Label', 'Time-frequency functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helptimefreq'');'); - uimenu( help_1, 'Label', 'Statistical functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpstatistics'');'); - uimenu( help_1, 'Label', 'Graphic interface builder functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpgui'');'); - uimenu( help_1, 'Label', 'Misc. command line functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpmisc'');'); - - uimenu( help_m, 'Label', 'EEGLAB license' , 'userdata', on, 'CallBack', 'pophelp(''eeglablicense.txt'', 1);'); + eegmenu( false, neuro_m, 'Label', 'From Biosemi BDF file (BIOSIG toolbox)', 'CallBack' , cb_biosig, 'Separator', 'on'); + eegmenu( false, neuro_m, 'Label', 'From EDF/EDF+/GDF files (BIOSIG toolbox)', 'CallBack', cb_biosig); + + eegmenu( false, epoch_m, 'Label', 'From MATLAB array or ASCII file' , 'CallBack', cb_importepoch); + eegmenu( false, event_m, 'Label', 'From MATLAB array or ASCII file' , 'CallBack', cb_importevent); + eegmenu( false, event_m, 'Label', 'From data channel' , 'CallBack', cb_chanevent); + eegmenu( false, event_m, 'Label', 'From Presentation .LOG file' , 'CallBack', cb_importpres); + eegmenu( false, event_m, 'Label', 'From E-Prime ASCII (text) file' , 'CallBack', cb_importevent); + eegmenu( false, event_m, 'Label', 'From ERPLAB text files' , 'CallBack', cb_importerplab); + + eegmenu( false, exportm, 'Label', '(for more use menu File > Manage EEGLAB extensions)', 'userdata', 'enable:off'); + eegmenu( false, exportm, 'Label', 'Data and ICA activity to text file' , 'CallBack', cb_export, 'separator', 'on'); + eegmenu( false, exportm, 'Label', 'Weight matrix to text file' , 'CallBack', cb_expica1); + eegmenu( false, exportm, 'Label', 'Inverse weight matrix to text file' , 'CallBack', cb_expica2); + eegmenu( false, exportm, 'Label', 'Events to text file' , 'CallBack', cb_expevents); + eegmenu( false, exportm, 'Label', 'Data to EDF/BDF/GDF file' , 'CallBack', cb_expdata, 'separator', 'on'); + + eegmenu( false, file_m, 'Label', 'Load existing dataset' , 'userdata', onnostudy, 'CallBack', cb_loadset, 'Separator', 'on'); + eegmenu( false, file_m, 'Label', 'Resave current dataset(s)' , 'userdata', ondatastudy, 'CallBack', cb_saveset); + eegmenu( false, file_m, 'Label', 'Save current dataset as' , 'userdata', ondata, 'CallBack', cb_savesetas); + eegmenu( false, file_m, 'Label', 'Clear dataset(s)' , 'userdata', ondata, 'CallBack', cb_delset); + + std2_m = eegmenu( false, file_m, 'Label', 'Create study' , 'userdata', on , 'Separator', 'on'); + eegmenu( false, std2_m, 'Label', 'Using all loaded datasets' , 'userdata', ondata , 'Callback', cb_study1); + eegmenu( false, std2_m, 'Label', 'Browse for datasets' , 'userdata', on , 'Callback', cb_study2); + eegmenu( false, std2_m, 'Label', 'Simple ERP STUDY' , 'userdata', on , 'Callback', cb_studyerp); + + eegmenu( false, file_m, 'Label', 'Load existing study' , 'userdata', on , 'CallBack', cb_loadstudy,'Separator', 'on' ); + eegmenu( false, file_m, 'Label', 'Save current study' , 'userdata', onstudy, 'CallBack', cb_savestudy1); + eegmenu( false, file_m, 'Label', 'Save current study as' , 'userdata', onstudy, 'CallBack', cb_savestudy2); + eegmenu( false, file_m, 'Label', 'Clear study / Clear all' , 'userdata', ondatastudy, 'CallBack', cb_clearstudy); + eegmenu( false, file_m, 'Label', 'Preferences' , 'userdata', on , 'CallBack', cb_editoptions, 'Separator', 'on'); + + hist_m = eegmenu( false, file_m, 'Label', 'History scripts' , 'userdata', on , 'Separator', 'on'); + eegmenu( false, hist_m, 'Label', 'Save dataset history script' , 'userdata', ondata , 'CallBack', cb_saveh1); + eegmenu( false, hist_m, 'Label', 'Save session history script' , 'userdata', ondatastudy, 'CallBack', cb_saveh2); + eegmenu( false, hist_m, 'Label', 'Run script' , 'userdata', on , 'CallBack', cb_runsc); + if isdeployed + eegmenu( false, hist_m, 'Label', 'Test compiled version' , 'userdata', on , 'CallBack', @test_compiled_version); + end + + if ~isdeployed + eegmenu( false, file_m, 'Label', 'Manage EEGLAB extensions' , 'userdata', on, 'CallBack', cb_plugin); + end + eegmenu( false, file_m, 'Label', 'Quit' , 'userdata', on , 'CallBack', cb_quit, 'Separator', 'on'); + + eegmenu( false, edit_m, 'Label', 'Dataset info' , 'userdata', ondata, 'CallBack', cb_editset); + eegmenu( versL, edit_m, 'Label', 'Event fields' , 'userdata', ondata, 'CallBack', cb_editeventf); + eegmenu( false, edit_m, 'Label', 'Event values' , 'userdata', ondata, 'CallBack', cb_editeventv); + eegmenu( versL, edit_m, 'Label', 'Adjust event latencies' , 'userdata', ondata, 'CallBack', cb_adjustevents); + eegmenu( false, edit_m, 'Label', 'About this dataset' , 'userdata', ondata, 'CallBack', cb_comments); + eegmenu( false, edit_m, 'Label', 'Channel locations' , 'userdata', ondatastudy, 'CallBack', cb_chanedit); + eegmenu( false, edit_m, 'Label', 'Select data' , 'userdata', ondatastudy, 'CallBack', cb_select, 'Separator', 'on'); + eegmenu( false, edit_m, 'Label', 'Select data using events' , 'userdata', ondata, 'CallBack', cb_rmdat); + eegmenu( false, edit_m, 'Label', 'Select epochs or events' , 'userdata', ondata, 'CallBack', cb_selectevent); + eegmenu( false, edit_m, 'Label', 'Copy current dataset' , 'userdata', ondata, 'CallBack', cb_copyset, 'Separator', 'on'); + eegmenu( false, edit_m, 'Label', 'Append datasets' , 'userdata', ondata, 'CallBack', cb_mergeset); + eegmenu( false, edit_m, 'Label', 'Delete dataset(s) from memory' , 'userdata', ondata, 'CallBack', cb_delset); + + eegmenu(~versL, tools_m, 'Label', '(Expand tool choices via "File > Preferences")' , 'userdata', 'enable:off'); + eegmenu( false, tools_m, 'Label', 'Change sampling rate' , 'userdata', ondatastudy, 'CallBack', cb_resample, 'Separator', 'on'); + + filter_m = eegmenu( false, tools_m, 'Label', 'Filter the data' , 'userdata', ondatastudy, 'tag', 'filter'); + eegmenu( false, filter_m, 'Label', 'Basic FIR filter (legacy)' , 'userdata', ondatastudy, 'CallBack', cb_eegfilt); + + eegmenu( false, tools_m, 'Label', 'Re-reference the data' , 'userdata', ondatastudy, 'CallBack', cb_reref); + eegmenu( false, tools_m, 'Label', 'Interpolate electrodes' , 'userdata', ondata, 'CallBack', cb_interp); + eegmenu( false, tools_m, 'Label', 'Inspect/reject data by eye' , 'userdata', ondata, 'CallBack', cb_eegplot, 'Separator', 'on'); + eegmenu( versL, tools_m, 'Label', 'Automatic channel rejection' , 'userdata', ondata, 'CallBack', cb_chanrej); + eegmenu( versL, tools_m, 'Label', 'Automatic continuous rejection' , 'userdata', ondata, 'CallBack', cb_rejcont); + eegmenu( versL, tools_m, 'Label', 'Automatic epoch rejection' , 'userdata', onepoch, 'CallBack', cb_autorej); + eegmenu( false, tools_m, 'Label', 'Decompose data by ICA' , 'userdata', ondatastudynoroi, 'CallBack', cb_runica, 'Separator', 'on'); + rej_m1 = eegmenu( versL, tools_m, 'Label', 'Reject data epochs' , 'userdata', onepoch); + rej_m2 = eegmenu( versL, tools_m, 'Label', 'Reject data using ICA' , 'userdata', ondata ); + + eegmenu( versL, rej_m1, 'Label', 'Reject data (all methods)' , 'userdata', onepoch, 'CallBack', cb_rejmenu1); + eegmenu( versL, rej_m1, 'Label', 'Reject by inspection' , 'userdata', onepoch, 'CallBack', cb_eegplotrej1); + eegmenu( versL, rej_m1, 'Label', 'Reject extreme values' , 'userdata', onepoch, 'CallBack', cb_eegthresh1); + eegmenu( versL, rej_m1, 'Label', 'Reject by linear trend/variance' , 'userdata', onepoch, 'CallBack', cb_rejtrend1); + eegmenu( versL, rej_m1, 'Label', 'Reject by probability' , 'userdata', onepoch, 'CallBack', cb_jointprob1); + eegmenu( versL, rej_m1, 'Label', 'Reject by kurtosis' , 'userdata', onepoch, 'CallBack', cb_rejkurt1); + eegmenu( versL, rej_m1, 'Label', 'Reject by spectra' , 'userdata', onepoch, 'CallBack', cb_rejspec1); + eegmenu( versL, rej_m1, 'Label', 'Export marks to ICA reject' , 'userdata', onepoch, 'CallBack', cb_rejsup1, 'separator', 'on'); + eegmenu( versL, rej_m1, 'Label', 'Reject marked epochs' , 'userdata', onepoch, 'CallBack', cb_rejsup2, 'separator', 'on', 'foregroundcolor', 'b'); + eegmenu(~versL, tools_m,'Label', 'Inspect/label components by map' , 'userdata', ondata , 'CallBack', cb_selectcomps); + eegmenu( versL, rej_m2, 'Label', 'Reject components by map' , 'userdata', ondata , 'CallBack', cb_selectcomps); + eegmenu( versL, rej_m2, 'Label', 'Reject data (all methods)' , 'userdata', onepoch, 'CallBack', cb_rejmenu2, 'Separator', 'on'); + eegmenu( versL, rej_m2, 'Label', 'Reject by inspection' , 'userdata', onepoch, 'CallBack', cb_eegplotrej2); + eegmenu( versL, rej_m2, 'Label', 'Reject extreme values' , 'userdata', onepoch, 'CallBack', cb_eegthresh2); + eegmenu( versL, rej_m2, 'Label', 'Reject by linear trend/variance' , 'userdata', onepoch, 'CallBack', cb_rejtrend2); + eegmenu( versL, rej_m2, 'Label', 'Reject by probability' , 'userdata', onepoch, 'CallBack', cb_jointprob2); + eegmenu( versL, rej_m2, 'Label', 'Reject by kurtosis' , 'userdata', onepoch, 'CallBack', cb_rejkurt2); + eegmenu( versL, rej_m2, 'Label', 'Reject by spectra' , 'userdata', onepoch, 'CallBack', cb_rejspec2); + eegmenu( versL, rej_m2, 'Label', 'Export marks to data reject' , 'userdata', onepoch, 'CallBack', cb_rejsup3, 'separator', 'on'); + eegmenu( versL, rej_m2, 'Label', 'Reject marked epochs' , 'userdata', onepoch, 'CallBack', cb_rejsup4, 'separator', 'on', 'foregroundcolor', 'b'); + + eegmenu( false, tools_m, 'Label', 'Remove components from data' , 'userdata', ondatastudy, 'CallBack', cb_subcomp ); + eegmenu( false, tools_m, 'Label', 'Extract epochs' , 'userdata', ondatastudy , 'CallBack', cb_epoch, 'Separator', 'on'); + eegmenu( false, tools_m, 'Label', 'Remove epoch baseline' , 'userdata', ondatastudy , 'CallBack', cb_rmbase); + + eegmenu( false, loc_m, 'Label', 'By name' , 'userdata', onchannel, 'CallBack', cb_topoblank1); + eegmenu( false, loc_m, 'Label', 'By number' , 'userdata', onchannel, 'CallBack', cb_topoblank2); + eegmenu( false, plot_m, 'Label', 'Channel data (scroll)' , 'userdata', ondata , 'CallBack', cb_eegplot1, 'Separator', 'on'); + eegmenu( false, plot_m, 'Label', 'Channel spectra and maps' , 'userdata', ondata , 'CallBack', cb_spectopo1); + eegmenu( false, plot_m, 'Label', 'Channel properties' , 'userdata', ondata , 'CallBack', cb_prop1); + eegmenu( false, plot_m, 'Label', 'Channel ERP image' , 'userdata', onepoch, 'CallBack', cb_erpimage1); + + ERP_m = eegmenu( false, plot_m, 'Label', 'Channel ERPs' , 'userdata', onepoch); + eegmenu( false, ERP_m, 'Label', 'With scalp maps' , 'CallBack', cb_timtopo); + eegmenu( false, ERP_m, 'Label', 'In scalp/rect. array' , 'CallBack', cb_plottopo); + + topo_m = eegmenu( false, plot_m, 'Label', 'ERP map series' , 'userdata', onepochchan); + eegmenu( false, topo_m, 'Label', 'In 2-D' , 'CallBack', cb_topoplot1); + eegmenu( false, topo_m, 'Label', 'In 3-D' , 'CallBack', cb_headplot1); + eegmenu( versL, plot_m, 'Label', 'Sum/Compare ERPs' , 'userdata', onepoch, 'CallBack', cb_comperp1); + eegmenu(~versL, plot_m, 'Label', 'Channel time-frequency' , 'CallBack', cb_timef1); + + eegmenu( false, plot_m, 'Label', 'Component activations (scroll)' , 'userdata', ondata , 'CallBack', cb_eegplot2,'Separator', 'on'); + eegmenu( false, plot_m, 'Label', 'Component spectra and maps' , 'userdata', ondatanoroi, 'CallBack', cb_spectopo2); + + tica_m = eegmenu( false, plot_m, 'Label', 'Component maps' , 'userdata', onchannelnoroi); + eegmenu( false, tica_m, 'Label', 'In 2-D' , 'CallBack', cb_topoplot2); + eegmenu( false, tica_m, 'Label', 'In 3-D' , 'CallBack', cb_headplot2); + eegmenu( false, plot_m, 'Label', 'Component properties' , 'userdata', ondata , 'CallBack', cb_prop2); + eegmenu( false, plot_m, 'Label', 'Component ERP image' , 'userdata', onepoch, 'CallBack', cb_erpimage2); + + ERPC_m = eegmenu( false, plot_m, 'Label', 'Component ERPs' , 'userdata', onepoch); + eegmenu( false, ERPC_m, 'Label', 'With component maps' , 'userdata', onepochnoroi, 'CallBack', cb_envtopo1); + eegmenu( false, ERPC_m, 'Label', 'With comp. maps (compare)' , 'userdata', onepochnoroi, 'CallBack', cb_envtopo2); + eegmenu( false, ERPC_m, 'Label', 'In rectangular array' , 'userdata', onepoch , 'CallBack', cb_plotdata2); + eegmenu( versL, plot_m, 'Label', 'Sum/Compare comp. ERPs' , 'userdata', onepochnoroi, 'userdata', onepoch, 'CallBack', cb_comperp2); + + stat_m = eegmenu( versL, plot_m, 'Label', 'Data statistics', 'Separator', 'on', 'userdata', ondata ); + eegmenu( versL, stat_m, 'Label', 'Channel statistics' , 'CallBack', cb_signalstat1); + eegmenu( versL, stat_m, 'Label', 'Component statistics' , 'CallBack', cb_signalstat2); + eegmenu( versL, stat_m, 'Label', 'Event statistics' , 'CallBack', cb_eventstat); + + spec_m = eegmenu( versL, plot_m, 'Label', 'Time-frequency transforms', 'Separator', 'on', 'userdata', ondata); + eegmenu( versL, spec_m, 'Label', 'Channel time-frequency' , 'CallBack', cb_timef1); + eegmenu( versL, spec_m, 'Label', 'Channel cross-coherence' , 'CallBack', cb_crossf1); + eegmenu( versL, spec_m, 'Label', 'Component time-frequency' , 'CallBack', cb_timef2,'Separator', 'on'); + eegmenu( versL, spec_m, 'Label', 'Component cross-coherence' , 'CallBack', cb_crossf2); + eegmenu(~versL, plot_m, 'Label', 'Component time-frequency' , 'CallBack', cb_timef2); + + eegmenu( false, std_m, 'Label', 'Edit study info' , 'userdata', onstudy, 'CallBack', cb_study3); + eegmenu( false, std_m, 'Label', 'Select/Edit study design(s)' , 'userdata', onstudy, 'CallBack', cb_studydesign); + eegmenu( false, std_m, 'Label', 'Precompute channel measures' , 'userdata', onstudy, 'CallBack', cb_precomp, 'separator', 'on'); + eegmenu( false, std_m, 'Label', 'Plot channel measures' , 'userdata', onstudy, 'CallBack', cb_chanplot); + eegmenu( false, std_m, 'Label', 'Precompute component measures' , 'userdata', onstudy, 'CallBack', cb_precomp2, 'separator', 'on'); + clust_m = eegmenu( false, std_m, 'Label', 'PCA clustering (original)' , 'userdata', onstudynoroi); + eegmenu( false, clust_m, 'Label', 'Build preclustering array' , 'userdata', onstudynoroi, 'CallBack', cb_preclust); + eegmenu( false, clust_m, 'Label', 'Cluster components' , 'userdata', onstudynoroi, 'CallBack', cb_clust); + eegmenu( false, std_m, 'Label', 'Edit/plot component clusters' , 'userdata', onstudy, 'CallBack', cb_clustedit); + + if ~isdeployed && ismatlab + %newerVersionMenu = eegmenu( false, help_m, 'Label', 'Upgrade to the Latest Version' , 'userdata', on, 'ForegroundColor', [0.6 0 0]); + eegmenu( false, help_m, 'Label', 'About EEGLAB' , 'userdata', on, 'CallBack', 'pophelp(''eeglab'');'); + eegmenu( false, help_m, 'Label', 'Check for EEGLAB update' , 'userdata', on, 'CallBack', 'eeglab_update;'); + eegmenu( false, help_m, 'Label', 'About EEGLAB help' , 'userdata', on, 'CallBack', 'pophelp(''eeg_helphelp'');'); + eegmenu( false, help_m, 'Label', 'EEGLAB menus' , 'userdata', on, 'CallBack', 'pophelp(''eeg_helpmenu'');','separator','on'); + + help_1 = eegmenu( false, help_m, 'Label', 'EEGLAB functions', 'userdata', on); + eegmenu( false, help_1, 'Label', 'Admin. functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpadmin'');'); + eegmenu( false, help_1, 'Label', 'Interactive pop_ functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helppop'');'); + eegmenu( false, help_1, 'Label', 'Signal processing functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpsigproc'');'); + eegmenu( false, help_1, 'Label', 'Group data (STUDY) functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpstudy'');'); + eegmenu( false, help_1, 'Label', 'Time-frequency functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helptimefreq'');'); + eegmenu( false, help_1, 'Label', 'Statistical functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpstatistics'');'); + eegmenu( false, help_1, 'Label', 'Graphic interface builder functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpgui'');'); + eegmenu( false, help_1, 'Label', 'Misc. command line functions' , 'userdata', on, 'Callback', 'pophelp(''eeg_helpmisc'');'); + + eegmenu( false, help_m, 'Label', 'EEGLAB license' , 'userdata', on, 'CallBack', 'pophelp(''eeglablicense.txt'', 1);'); + eegmenu( false, help_m, 'Label', 'EEGLAB tutorial' , 'userdata', on, 'CallBack', 'tutorial;', 'Separator', 'on'); + eegmenu( false, help_m, 'Label', 'Email the EEGLAB team' , 'userdata', on, 'CallBack', 'web(''mailto:eeglab@sccn.ucsd.edu'');'); else - uimenu( help_m, 'Label', 'About EEGLAB' , 'userdata', on, 'CallBack', 'abouteeglab;'); - uimenu( help_m, 'Label', 'EEGLAB license' , 'userdata', on, 'CallBack', 'pophelp(''eeglablicense.txt'', 1);'); - end; - - uimenu( help_m, 'Label', 'EEGLAB tutorial' , 'userdata', on, 'CallBack', 'tutorial;', 'Separator', 'on'); - uimenu( help_m, 'Label', 'Email the EEGLAB team' , 'userdata', on, 'CallBack', 'web(''mailto:eeglab@sccn.ucsd.edu'');'); -end; - -if iseeglabdeployed2 - disp('Adding FIELDTRIP toolbox functions'); - disp('Adding BIOSIG toolbox functions'); - disp('Adding FILE-IO toolbox functions'); - funcname = { 'eegplugin_VisEd' ... - 'eegplugin_eepimport' ... - 'eegplugin_bdfimport' ... - 'eegplugin_brainmovie' ... - 'eegplugin_bva_io' ... - 'eegplugin_ctfimport' ... - 'eegplugin_dipfit' ... - 'eegplugin_erpssimport' ... - 'eegplugin_fmrib' ... - 'eegplugin_iirfilt' ... - 'eegplugin_ascinstep' ... - 'eegplugin_loreta' ... - 'eegplugin_miclust' ... - 'eegplugin_4dneuroimaging' }; + eegmenu( false, help_m, 'Label', 'About EEGLAB' , 'userdata', on, 'CallBack', 'abouteeglab;'); + eegmenu( false, help_m, 'Label', 'EEGLAB license' , 'userdata', on, 'CallBack', 'pophelp(''eeglablicense.txt'', 1);'); + eegmenu( false, help_m, 'Label', 'EEGLAB tutorial' , 'userdata', on, 'CallBack', 'tutorial;', 'Separator', 'on'); + end + +end + +statusconnection = 1; +eeglabVersionStatus = []; +if isdeployed || (exist('ismcc') && ismcc) + disp('Loading plugins'); + funcname = { ... + @eegplugin_eepimport, ... + @eegplugin_iclabel, ... + @eegplugin_VisEd, ... + @eegplugin_bids, ... + @eegplugin_bva_io, ... + @eegplugin_clean_rawdata, ... + @eegplugin_dipfit, ... + @eegplugin_egilegacy, ... + @eegplugin_firfilt, ... + @eegplugin_iirfilt, ... + @eegplugin_musedirect, ... + @eegplugin_musemonitor, ... + @eegplugin_neuroscanio, ... + @eegplugin_scd, ... + @eegplugin_snapmaster, ... + @eegplugin_xdfimport, ... + @eegplugin_mffmatlabio, ... + }; for indf = 1:length(funcname) - try - vers = feval(funcname{indf}, gcf, trystrs, catchstrs); - disp(['EEGLAB: adding "' vers '" plugin' ]); - catch - feval(funcname{indf}, gcf, trystrs, catchstrs); - disp(['EEGLAB: adding plugin function "' funcname{indf} '"' ]); - end; - end; + pluginfun = funcname{indf}; + pluginname = func2str(pluginfun); + try + outargs = nargout(pluginfun); + if outargs == 1 + vers = feval(pluginfun, gcf, trystrs, catchstrs); + disp(['EEGLAB: adding "' vers '" plugin' ]); + else + feval(funcname{indf}, gcf, trystrs, catchstrs); + disp(['EEGLAB: adding plugin function "' pluginname '"' ]); + end + catch e + disp(['EEGLAB: Could not load "' pluginname '": ' e.message]); + end + end else pluginlist = []; plugincount = 1; - p = mywhich('eeglab.m'); - p = p(1:findstr(p,'eeglab.m')-1); - if strcmpi(p, './') || strcmpi(p, '.\'), p = [ pwd filesep ]; end; + eeglabp = fileparts(mywhich('eeglab.m')); + + % scan plugin folder + % ------------------ + dircontent = dir(fullfile(eeglabp, 'plugins')); + if ~isfield(dircontent, 'folder') + [dircontent(:).folder] = deal(fullfile(eeglabp, 'plugins')); + end - % scan deactivated plugin folder - % ------------------------------ - dircontent = dir(fullfile(p, 'deactivatedplugins')); - dircontent = { dircontent.name }; - for index = 1:length(dircontent) - funcname = ''; - pluginVersion = ''; - if exist([p 'deactivatedplugins' filesep dircontent{index}]) == 7 - if ~strcmpi(dircontent{index}, '.') & ~strcmpi(dircontent{index}, '..') - tmpdir = dir([ p 'deactivatedplugins' filesep dircontent{index} filesep 'eegplugin*.m' ]); - [ pluginName pluginVersion ] = parsepluginname(dircontent{index}); - if ~isempty(tmpdir) - funcname = tmpdir(1).name(1:end-2); - end; - end; - else - if ~isempty(findstr(dircontent{index}, 'eegplugin')) && dircontent{index}(end) == 'm' - funcname = dircontent{index}(1:end-2); % remove .m - [ pluginName pluginVersion ] = parsepluginname(dircontent{index}(10:end-2)); - end; - end; - if ~isempty(pluginVersion) - pluginlist(plugincount).plugin = pluginName; - pluginlist(plugincount).version = pluginVersion; - pluginlist(plugincount).foldername = dircontent{index}; - if ~isempty(funcname) - pluginlist(plugincount).funcname = funcname(10:end); - else pluginlist(plugincount).funcname = ''; + % scan local plugin folder + % ------------------------ + if ~isequal(pwd, eeglabp) + dircontent2 = dir(fullfile(pwd, 'plugins')); + if ~isempty(dircontent2) + fprintf(2, 'WARNING: plugins in current folders may shadow plugins installed in EEGLAB plugins folder\n'); + if ~isfield(dircontent2, 'folder') + [dircontent2(:).folder] = deal(fullfile(pwd, 'plugins')); end - if length(pluginlist(plugincount).funcname) > 1 && pluginlist(plugincount).funcname(1) == '_' - pluginlist(plugincount).funcname(1) = []; - end; - pluginlist(plugincount).status = 'deactivated'; - plugincount = plugincount+1; - end; - end; + dircontent = [dircontent;dircontent2]; + end + end + + pluginstats = []; + if option_checkversion && ismatlab + disp('Retrieving plugin versions from server...'); + try + [pluginTmp, eeglabVersionStatus] = plugin_getweb('startup', pluginlist); + catch + disp('Issue with retrieving statistics for extensions'); + pluginTmp = []; + end + if ~isempty(pluginTmp) && isfield(pluginTmp, 'name') && isfield(pluginTmp, 'version') + pluginstats.name = { pluginTmp.name }; + pluginstats.version = { pluginTmp.version }; + end + end - % scan plugin folder - % ------------------ - dircontent = dir(fullfile(p, 'plugins')); - dircontent = { dircontent.name }; for index = 1:length(dircontent) % find function % ------------- funcname = ''; pluginVersion = []; - if exist([p 'plugins' filesep dircontent{index}]) == 7 - if ~strcmpi(dircontent{index}, '.') & ~strcmpi(dircontent{index}, '..') - newpath = [ 'plugins' filesep dircontent{index} ]; - tmpdir = dir([ p 'plugins' filesep dircontent{index} filesep 'eegplugin*.m' ]); + if exist(fullfile(dircontent(index).folder, dircontent(index).name), 'dir') + if ~strcmpi(dircontent(index).name, '.') && ~strcmpi(dircontent(index).name, '..') + tmpdir = dir(fullfile(dircontent(index).folder, dircontent(index).name, 'eegplugin*.m')); - addpathifnotinlist(fullfile(eeglabpath, newpath)); - [ pluginName pluginVersion ] = parsepluginname(dircontent{index}); if ~isempty(tmpdir) %myaddpath(eeglabpath, tmpdir(1).name, newpath); funcname = tmpdir(1).name(1:end-2); - end; + end + addpathifnotinlist(fullfile(dircontent(index).folder, dircontent(index).name)); + [ pluginName, pluginVersion ] = parsepluginname(dircontent(index).name, funcname(11:end)); % special case of subfolder for Fieldtrip % --------------------------------------- - if ~isempty(findstr(lower(dircontent{index}), 'fieldtrip')) - addpathifnotexist( fullfile(eeglabpath, newpath, 'compat') , 'electrodenormalize' ); - addpathifnotexist( fullfile(eeglabpath, newpath, 'forward'), 'ft_sourcedepth.m'); - addpathifnotexist( fullfile(eeglabpath, newpath, 'utilities'), 'ft_datatype.m'); + if ~isempty(findstr(lower(dircontent(index).name), 'fieldtrip')) && isempty(findstr(lower(dircontent(index).name), 'rest')) + addpathifnotexist( fullfile(dircontent(index).folder, dircontent(index).name, 'compat') , 'electrodenormalize' ); + addpathifnotexist( fullfile(dircontent(index).folder, dircontent(index).name, 'forward'), 'ft_sourcedepth.m'); + addpathifnotexist( fullfile(dircontent(index).folder, dircontent(index).name, 'utilities'), 'ft_datatype.m'); + addpathifnotexist( fullfile(dircontent(index).folder, dircontent(index).name, 'plotting'), 'ft_plot_mesh.m'); ptopoplot = fileparts(mywhich('cbar')); ptopoplot2 = fileparts(mywhich('topoplot')); if ~isequal(ptopoplot, ptopoplot2) addpath(ptopoplot); - end; - end; + end + end % special case of subfolder for BIOSIG % ------------------------------------ - if ~isempty(findstr(lower(dircontent{index}), 'biosig')) && isempty(findstr(lower(dircontent{index}), 'biosigplot')) - addpathifnotexist( fullfile(eeglabpath, newpath, 'biosig', 't200_FileAccess'), 'sopen.m'); - addpathifnotexist( fullfile(eeglabpath, newpath, 'biosig', 't250_ArtifactPreProcessingQualityControl'), 'regress_eog.m' ); - addpathifnotexist( fullfile(eeglabpath, newpath, 'biosig', 'doc'), 'DecimalFactors.txt'); - end; + if ~isempty(findstr(lower(dircontent(index).name), 'biosig')) && isempty(strfind(lower(dircontent(index).name), 'biosigplot')) + addpathifnotexist( fullfile(dircontent(index).folder, dircontent(index).name, 'biosig', 't200_FileAccess'), 'sopen.m'); + addpathifnotexist( fullfile(dircontent(index).folder, dircontent(index).name, 'biosig', 't250_ArtifactPreProcessingQualityControl'), 'regress_eog.m' ); + addpathifnotexist( fullfile(dircontent(index).folder, dircontent(index).name, 'biosig', 'doc'), 'DecimalFactors.txt'); + end - end; + end else - if ~isempty(findstr(dircontent{index}, 'eegplugin')) && dircontent{index}(end) == 'm' - funcname = dircontent{index}(1:end-2); % remove .m - [ pluginName pluginVersion ] = parsepluginname(dircontent{index}(10:end-2)); - end; - end; + if ~isempty(findstr(dircontent(index).name, 'eegplugin')) && dircontent(index).name(end) == 'm' + funcname = dircontent(index).name(1:end-2); % remove .m + [ pluginName, pluginVersion ] = parsepluginname(dircontent(index).name(10:end-2)); + end + end % execute function % ---------------- if ~isempty(pluginVersion) || ~isempty(funcname) if isempty(funcname) - disp([ 'EEGLAB: adding "' pluginName '" to the path; subfolders (if any) might be missing from the path' ]); + fprintf([ 'EEGLAB: adding "' pluginName '" v' pluginVersion ' to the path' ]); pluginlist(plugincount).plugin = pluginName; pluginlist(plugincount).version = pluginVersion; - pluginlist(plugincount).foldername = dircontent{index}; + pluginlist(plugincount).foldername = dircontent(index).name; pluginlist(plugincount).status = 'ok'; + if ~isempty(pluginstats) + indPlugin = strmatch(lower(pluginlist(plugincount).plugin), lower(pluginstats.name), 'exact'); + else + indPlugin = []; + end + if length(indPlugin) == 1 + if ~strcmpi(pluginVersion, pluginstats.version{indPlugin}) + fprintf(2, ' - new version %s available\n', pluginstats.version{indPlugin}); + else + fprintf('\n'); + end + else + fprintf('\n'); + end plugincount = plugincount+1; else pluginlist(plugincount).plugin = pluginName; pluginlist(plugincount).version = pluginVersion; - vers = pluginlist(plugincount).version; % version vers2 = ''; status = 'ok'; - try, - %eval( [ 'vers2 =' funcname '(gcf, trystrs, catchstrs);' ]); - vers2 = feval(funcname, gcf, trystrs, catchstrs); - catch - try, - eval( [ funcname '(gcf, trystrs, catchstrs)' ]); + if ~strcmpi(onearg, 'nogui') + try + %eval( [ 'vers2 =' funcname '(gcf, trystrs, catchstrs);' ]); + vers2 = feval(funcname, gcf, trystrs, catchstrs); + [~, vers2] = parsepluginname(vers2); catch - disp([ 'EEGLAB: error while adding plugin "' funcname '"' ] ); - disp([ ' ' lasterr] ); - status = 'error'; - end; - end; + try + eval( [ funcname '(gcf, trystrs, catchstrs)' ]); + catch + disp([ 'EEGLAB: error while adding plugin "' funcname '"' ] ); + disp([ ' ' lasterr] ); + status = 'error'; + end + end + end + if isempty(pluginlist(plugincount).version) + pluginlist(plugincount).version = vers2; + elseif ~isempty(vers2) + if ~isequal(pluginlist(plugincount).version, vers2) + fprintf('WARNING: for plugin "%s" version in the folder name "%s" and in the eegplugin_ file "%s" differ\n', pluginlist(plugincount).plugin, pluginlist(plugincount).version,vers2); + end + end pluginlist(plugincount).funcname = funcname(10:end); - pluginlist(plugincount).foldername = dircontent{index}; - [tmp pluginlist(plugincount).versionfunc] = parsepluginname(vers2); + pluginlist(plugincount).foldername = dircontent(index).name; if length(pluginlist(plugincount).funcname) > 1 && pluginlist(plugincount).funcname(1) == '_' pluginlist(plugincount).funcname(1) = []; - end; + end if strcmpi(status, 'ok') - if isempty(vers), vers = pluginlist(plugincount).versionfunc; end; - if isempty(vers), vers = '?'; end; - fprintf('EEGLAB: adding "%s" v%s (see >> help %s)\n', ... + vers = pluginlist(plugincount).version; % version + if isempty(vers), vers = '?'; end + fprintf('EEGLAB: adding "%s" v%s (see >> help %s)', ... pluginlist(plugincount).plugin, vers, funcname); - end; + if ~isempty(pluginstats) + indPlugin = strmatch(lower(pluginlist(plugincount).plugin), lower(pluginstats.name), 'exact'); + if length(indPlugin) == 1 + if ~strcmpi(vers, pluginstats.version{indPlugin}) + fprintf(2, ' - new version %s available\n', pluginstats.version{indPlugin}); + else fprintf('\n'); + end + else fprintf('\n'); + end + else fprintf('\n'); + end + end pluginlist(plugincount).status = status; plugincount = plugincount+1; - end; - end; - end; + end + end + end global PLUGINLIST; PLUGINLIST = pluginlist; -end; % iseeglabdeployed2 + + % add menus for plugins to install + % -------------------------------- + if ismatlab && ~strcmpi(onearg, 'nogui') + if ~exist('mff_import', 'file') + neuro_m = findobj(W_MAIN, 'tag', 'import data'); + cb_mff = [ 'if ~plugin_askinstall(''mffmatlabio'', ''mff_import''), return; end;' ... + 'eval(char(get(findobj(''label'', ''Import Magstim/EGI .mff file''), ''callback'')));' ]; + eegmenu( false, neuro_m, 'Label', 'Import Magstim/EGI .mff file', 'CallBack', cb_mff, 'separator', 'on'); + end + if ~exist('eegplugin_neuroscanio', 'file') + neuro_m = findobj(W_MAIN, 'tag', 'import data'); + neuroscan_check = 'if ~plugin_askinstall(''neuroscanio'', ''eegplugin_neuroscanio''), return; end;'; + cb_neuroscan1 = [ neuroscan_check 'eval(char(get(findobj(''label'', ''From Neuroscan .CNT file''), ''callback'')));' ]; + cb_neuroscan2 = [ neuroscan_check 'eval(char(get(findobj(''label'', ''From Neuroscan .EEG file''), ''callback'')));' ]; + eegmenu( false, neuro_m, 'Label', 'From Neuroscan .CNT file', 'CallBack', cb_neuroscan1, 'Separator', 'on'); + eegmenu( false, neuro_m, 'Label', 'From Neuroscan .EEG file', 'CallBack', cb_neuroscan2); + end + if ~exist('eegplugin_firfilt', 'file') + neuro_m = findobj(W_MAIN, 'tag', 'filter'); + cb_filter = [ 'if ~plugin_askinstall(''firfilt'', ''eegplugin_firfilt''), return; end;' ... + 'eval(char(get(findobj(''label'', ''Basic FIR filter (new, default)''), ''callback'')));' ]; + eegmenu( false, neuro_m, 'Label', 'Basic FIR filter (new, default)', 'CallBack', cb_filter, 'separator', 'on'); + end + if ~exist('eegplugin_iclabel', 'file') + fprintf(2, 'Warning: ICLabel default plugin missing (probably due to downloading zip file from Github). Install manually.\n'); + end + if ~exist('eegplugin_clean_rawdata', 'file') + fprintf(2, 'Warning: Clean Rawdata plugin missing (probably due to downloading zip file from Github). Install manually.\n'); + end + if ~exist('pop_dipfit_settings', 'file') + neuro_m = findobj(W_MAIN, 'tag', 'tools'); + cb_dipfit = 'if ~plugin_askinstall(''dipfit'', ''pop_dipfit_settings''), return; end;' ; + eegmenu( false, neuro_m, 'Label', 'Locate dipoles using DIPFIT 2.x', 'CallBack', cb_dipfit, 'separator', 'on'); + end + if ~exist('pop_loadbva', 'file') + neuro_m = findobj(W_MAIN, 'tag', 'import data'); + cb_bva1 = [ 'if ~plugin_askinstall(''bva-io'', ''pop_loadbva''), return; end;' ... + 'eval(char(get(findobj(''label'', ''From Brain Vis. Rec. .vhdr file''), ''callback'')));' ]; + cb_bva2 = [ 'if ~plugin_askinstall(''bva-io'', ''pop_loadbva''), return; end;' ... + 'eval(char(get(findobj(''label'', ''From Brain Vis. Anal. Matlab file''), ''callback'')));' ]; + eegmenu( false, neuro_m, 'Label', 'From Brain Vis. Rec. .vhdr file', 'CallBack', cb_bva1, 'separator', 'on'); + eegmenu( false, neuro_m, 'Label', 'From Brain Vis. Anal. Matlab file', 'CallBack', cb_bva2); + end + end +end + +% Path exception for BIOSIG (sending BIOSIG down into the path) +biosigpathlast; % fix str2double issue + +% push SIFT path last for dipplot +dipplotpath = fileparts( which('dipplot') ); +dipfitpath = fileparts( which('dipfit_1_to_2') ); +if ~strcmp(dipplotpath,dipfitpath) + addpath(dipfitpath,'-begin'); +end + +if strcmpi(onearg, 'nogui') + return; +end -if ~ismatlab, return; end; % add other import ... % -------------------- cb_others = [ 'pophelp(''troubleshooting_data_formats'');' ]; -uimenu( import_m, 'Label', 'Using the FILE-IO interface', 'CallBack', cb_fileio, 'separator', 'on'); -uimenu( import_m, 'Label', 'Using the BIOSIG interface' , 'CallBack', cb_biosig); -uimenu( import_m, 'Label', 'Troubleshooting data formats...', 'CallBack', cb_others); +eegmenu( false, import_m, 'Label', 'Using the FILE-IO interface', 'CallBack', cb_fileio, 'separator', 'on'); +eegmenu( false, import_m, 'Label', 'Using the BIOSIG interface' , 'CallBack', cb_biosig); +eegmenu( false, import_m, 'Label', 'Troubleshooting data formats...', 'CallBack', cb_others); % changing plugin menu color % -------------------------- @@ -1050,127 +1220,40 @@ editsub_m = findobj('parent', edit_m); exportsub_m = findobj('parent', exportm); filter_m = findobj('parent', filter_m); + icadefs; % containing PLUGINMENUCOLOR -if length(fourthsub_m) > 11, set(fourthsub_m(1:end-11), 'foregroundcolor', PLUGINMENUCOLOR); end; -if length(plotsub_m) > 17, set(plotsub_m (1:end-17), 'foregroundcolor', PLUGINMENUCOLOR); end; -if length(importsub_m) > 9, set(importsub_m(1:end-9) , 'foregroundcolor', PLUGINMENUCOLOR); end; -if length(epochsub_m ) > 3 , set(epochsub_m (1:end-3 ), 'foregroundcolor', PLUGINMENUCOLOR); end; -if length(eventsub_m ) > 4 , set(eventsub_m (1:end-4 ), 'foregroundcolor', PLUGINMENUCOLOR); end; -if length(exportsub_m) > 4 , set(exportsub_m(1:end-4 ), 'foregroundcolor', PLUGINMENUCOLOR); end; -if length(editsub_m) > 10, set(editsub_m( 1:end-10), 'foregroundcolor', PLUGINMENUCOLOR); end; -if length(filter_m) > 3 , set(filter_m (1:end-1 ), 'foregroundcolor', PLUGINMENUCOLOR); end; - -EEGMENU = uimenu( set_m, 'Label', '------', 'Enable', 'off'); -eval('set(W_MAIN, ''userdat'', { EEGUSERDAT{1} EEGMENU javaobj });'); +if versL, tm = 14; else tm = 16; end +if length(fourthsub_m) > tm, set(fourthsub_m(1:end-tm), 'foregroundcolor', PLUGINMENUCOLOR); end +if length(plotsub_m) > 17, set(plotsub_m (1:end-17), 'foregroundcolor', PLUGINMENUCOLOR); end +if length(importsub_m) > 4, set(importsub_m(1:end-4) , 'foregroundcolor', PLUGINMENUCOLOR); end +if length(epochsub_m ) > 3 , set(epochsub_m (1:end-3 ), 'foregroundcolor', PLUGINMENUCOLOR); end +if length(eventsub_m ) > 4 , set(eventsub_m (1:end-4 ), 'foregroundcolor', PLUGINMENUCOLOR); end +if length(exportsub_m) > 4 , set(exportsub_m(1:end-4 ), 'foregroundcolor', PLUGINMENUCOLOR); end +if length(editsub_m) > 10, set(editsub_m( 1:end-10), 'foregroundcolor', PLUGINMENUCOLOR); end +if length(filter_m) > 3 , set(filter_m (1:end-1 ), 'foregroundcolor', PLUGINMENUCOLOR); end + +EEGMENU = eegmenu( false, set_m, 'Label', '------', 'Enable', 'off'); +eval('set(W_MAIN, ''userdat'', { EEGUSERDAT{1} EEGMENU });'); eeglab('redraw'); if nargout < 1 clear ALLEEG; -end; +end -%% automatic updater -try - [dummy eeglabVersionNumber currentReleaseDateString] = eeg_getversion; - if isempty(eeglabVersionNumber) - eeglabVersionNumber = 'dev'; - end; - eeglabUpdater = up.updater(eeglabVersionNumber, 'http://sccn.ucsd.edu/eeglab/updater/latest_version.php', 'EEGLAB', currentReleaseDateString); - - % create a new GUI item (e.g. under Help) - %newerVersionMenu = uimenu(help_m, 'Label', 'Upgrade to the Latest Version', 'visible', 'off', 'userdata', 'startup:on;study:on'); - - % set the callback to bring up the updater GUI - icadefs; % for getting background color - eeglabFolder = fileparts(mywhich('eeglab.m')); - %eeglabUpdater.menuItemHandle = []; %newerVersionMenu; - %eeglabUpdater.menuItemCallback = {@command_on_update_menu_click, eeglabUpdater, eeglabFolder, true, BACKEEGLABCOLOR}; - - % place it in the base workspace. - assignin('base', 'eeglabUpdater', eeglabUpdater); - - % only start timer if the function is called from the command line - % (which means that the stack should only contain one element) - stackVar = dbstack; - if length(stackVar) == 1 - if option_checkversion - eeglabUpdater.checkForNewVersion({'eeglab_event' 'setup'}); - if strcmpi(eeglabVersionNumber, 'dev') - return; - end; - newMajorRevision = 0; - if ~isempty(eeglabUpdater.newMajorRevision) - fprintf('\nA new major version of EEGLAB (EEGLAB%s - beta) is now available.\n', eeglabUpdater.newMajorRevision); - newMajorRevision = 1; - end; - if eeglabUpdater.newerVersionIsAvailable - eeglabv = num2str(eeglabUpdater.latestVersionNumber); - posperiod = find(eeglabv == '.'); - if isempty(posperiod), posperiod = length(eeglabv)+1; eeglabv = [ eeglabv '.0' ]; end; - if length(eeglabv(posperiod+1:end)) < 2, eeglabv = [ eeglabv '0' ]; end; - %if length(eeglabv(posperiod+1:end)) < 3, eeglabv = [ eeglabv '0' ]; end; - eeglabv = [ eeglabv(1:posperiod+1) '.' eeglabv(posperiod+2) ]; %'.' eeglabv(posperiod+3) ]; - - stateWarning = warning('backtrace'); - warning('backtrace', 'off'); - if newMajorRevision - fprintf('\n'); - warning( sprintf(['\nA critical revision of EEGLAB%d (%s) is also available here\n' ... - 'See Release notes for more informations\n' ... - 'You may disable this message using the Option menu\n' ], ... - floor(eeglabVersionNumber), eeglabv, eeglabUpdater.downloadUrl, ... - [ 'http://sccn.ucsd.edu/wiki/EEGLAB_revision_history_version_13' ])); - else - warning( sprintf(['\nA newer version of EEGLAB (%s) is available here\n' ... - 'See Release notes for more informations\n' ... - 'You may disable this message using the Option menu\n' ], ... - eeglabv, eeglabUpdater.downloadUrl, ... - [ 'http://sccn.ucsd.edu/wiki/EEGLAB_revision_history_version_13' ])); - end; - warning('backtrace', stateWarning.state); - - % make the Help menu item dark red - set(help_m, 'foregroundColor', [0.6, 0 0]); - elseif isempty(eeglabUpdater.lastTimeChecked) - fprintf('Could not check for the latest EEGLAB version (internet may be disconnected).\n'); - fprintf('To prevent long startup time, disable checking for new EEGLAB version (FIle > Memory and other options).\n'); - else - if ~newMajorRevision - fprintf('You are using the latest version of EEGLAB.\n'); - else - fprintf('You are currently using the latest revision of EEGLAB%d (no critical update available).\n', floor(eeglabVersionNumber)); - end; - end; - else - eeglabtimers = timerfind('name', 'eeglabupdater'); - if ~isempty(eeglabtimers) - stop(eeglabtimers); - delete(eeglabtimers); - end; - % This is disabled because it cause Matlab to hang in case - % there is no connection or the connection is available but not - % usable - % start(timer('TimerFcn','try, eeglabUpdater.checkForNewVersion({''eeglab_event'' ''setup''}); catch, end; clear eeglabUpdater;', 'name', 'eeglabupdater', 'StartDelay', 20.0)); - end; - end; -catch - if option_checkversion - fprintf('Updater could not be initialized.\n'); - end; -end; +% check if update is available +if ismatlab + eeglab_update(eeglabVersionStatus); +end % REMOVED MENUS - %uimenu( tools_m, 'Label', 'Automatic comp. reject', 'enable', 'off', 'CallBack', '[EEG LASTCOM] = pop_rejcomp(EEG); eegh(LASTCOM); if ~isempty(LASTCOM), eeg_store(CURRENTSET); end;'); - %uimenu( tools_m, 'Label', 'Reject (synthesis)' , 'Separator', 'on', 'CallBack', '[EEG LASTCOM] = pop_rejall(EEG); eegh(LASTCOM); if ~isempty(LASTCOM), eeg_store; end; eeglab(''redraw'');'); - - function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installDirectory, goOneFolderLevelIn, backGroundColor) - postInstallCallbackString = 'clear all function functions; eeglab'; - eeglabUpdater.launchGui(installDirectory, goOneFolderLevelIn, backGroundColor, postInstallCallbackString); - + %eegmenu( false, tools_m, 'Label', 'Automatic comp. reject', 'enable', 'off', 'CallBack', '[EEG LASTCOM] = pop_rejcomp(EEG); eegh(LASTCOM); if ~isempty(LASTCOM), eeg_store(CURRENTSET); end;'); + %eegmenu( false, tools_m, 'Label', 'Reject (synthesis)' , 'Separator', 'on', 'CallBack', '[EEG LASTCOM] = pop_rejall(EEG); eegh(LASTCOM); if ~isempty(LASTCOM), eeg_store; end; eeglab(''redraw'');'); + % % -------------------- % draw the main figure % -------------------- -function tb = eeg_mainfig(onearg); +function eeg_mainfig(onearg); icadefs; COLOR = BACKEEGLABCOLOR; @@ -1179,7 +1262,6 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD WINYDEC = 13; NBLINES = 16; WINY = WINYDEC*NBLINES; -javaChatFlag = 1; BORDERINT = 4; BORDEREXT = 10; @@ -1196,19 +1278,36 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD FONTSIZE = FONTSIZE+2; WINMAXX = WINMAXX*1.3; WINY = WINY*1.3; - end; + end else FONTNAME = ''; FONTSIZE = 11; -end; +end +if ~ismatlab + WINMAXX = WINMAXX*1.35; + WINY = WINY*1.4; +end hh = findobj('tag', 'EEGLAB'); if ~isempty(hh) disp('EEGLAB warning: there can be only one EEGLAB window, closing old one'); close(hh); -end; +end + +% determine the text for the revision +[txtVersion, numVersion ] = eeg_getversion; +if ~isempty(numVersion) + txtVersion = [ 'EEGLAB v' txtVersion ]; +else + txtVersion = [ 'EEGLAB ' txtVersion ]; +end +if ~ismatlab && ismac + txtVersion = [ txtVersion ' - menu is on the top bar' ]; +end + +% create figures if strcmpi(onearg, 'remote') - figure( 'name', [ 'EEGLAB v' eeg_getversion ], ... + figure( 'name', txtVersion, ... 'numbertitle', 'off', ... 'Position',[200 100 (WINMINX+WINMAXX+2*BORDERINT+2*BORDEREXT) 30 ], ... 'color', COLOR, ... @@ -1216,13 +1315,13 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD 'Userdata', {[] []}); %'resize', 'off', ... return; -end; +end W_MAIN = figure('Units','points', ... ... % 'Colormap','gray', ... 'PaperPosition',[18 180 576 432], ... 'PaperUnits','points', ... - 'name', [ 'EEGLAB v' eeg_getversion ], ... + 'name', txtVersion, ... 'numbertitle', 'off', ... 'Position',[200 100 (WINMINX+WINMAXX+2*BORDERINT+2*BORDEREXT) (WINY+2*BORDERINT+2*BORDEREXT) ], ... 'color', COLOR, ... @@ -1233,231 +1332,172 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD % java chat eeglab_options; -if option_chat == 1 - if is_sccn - disp('Starting chat...'); - tmpp = fileparts(mywhich('startpane.m')); - if isempty(tmpp) || ~ismatlab - disp('Cannot start chat'); - tb = []; - else - disp(' ----------------------------------- '); - disp('| EEGLAB chat 0.9 |'); - disp('| The chat currently only works |'); - disp('| at the University of CA San Diego |'); - disp(' ----------------------------------- '); - - javaaddpath(fullfile(tmpp, 'Chat_with_pane.jar')); - eval('import client.EEGLABchat.*;'); - eval('import client.VisualToolbar;'); - eval('import java.awt.*;'); - eval('import javax.swing.*;'); - - try - tb = VisualToolbar('137.110.244.26'); - F = W_MAIN; - tb.setPreferredSize(Dimension(0, 75)); - - javacomponent(tb,'South',F); - javaclose = ['userdat = get(gcbf, ''userdata'');' ... - 'try,'... - ' tb = userdat{3};' ... - 'clear userdat; delete(gcbf); tb.close; clear tb;'... - 'catch,end;']; - set(gcf, 'CloseRequestFcn',javaclose); - - refresh(F); - catch, - tb = []; - end; - end; - else - tb = []; - end; -else - tb = []; -end; -try, +try set(W_MAIN, 'NextPlot','new'); -catch, end; - -if ismatlab - BackgroundColor = get(gcf, 'color'); %[0.701960784313725 0.701960784313725 0.701960784313725]; - H_MAIN(1) = uicontrol('Parent',W_MAIN, ... - 'Units','points', ... - 'BackgroundColor',COLOR, ... - 'ListboxTop',0, ... - 'HorizontalAlignment', 'left',... - 'Position',[BORDEREXT BORDEREXT (WINMINX+WINMAXX+2*BORDERINT) (WINY)], ... - 'Style','frame', ... - 'Tag','Frame1'); - set(H_MAIN(1), 'unit', 'normalized'); - geometry = { [1] [1] [1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1] }; - listui = { { 'style', 'text', 'string', 'Parameters of the current set', 'tag', 'win0' } { } ... - { 'style', 'text', 'tag', 'win1', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win2', 'string', 'Channels per frame', 'userdata', 'datinfo'} ... - { 'style', 'text', 'tag', 'val2', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win3', 'string', 'Frames per epoch', 'userdata', 'datinfo'} ... - { 'style', 'text', 'tag', 'val3', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win4', 'string', 'Epochs', 'userdata', 'datinfo'} ... - { 'style', 'text', 'tag', 'val4', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win5', 'string', 'Events', 'userdata', 'datinfo'} ... - { 'style', 'text', 'tag', 'val5', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win6', 'string', 'Sampling rate (Hz)', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'val6', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win7', 'string', 'Epoch start (sec)', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'val7', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win8', 'string', 'Epoch end (sec)', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'val8', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win9', 'string', 'Average reference', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'val9', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win10', 'string', 'Channel locations', 'userdata', 'datinfo'} ... - { 'style', 'text', 'tag', 'val10', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win11', 'string', 'ICA weights', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'val11', 'string', ' ', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'win12', 'string', 'Dataset size (Mb)', 'userdata', 'datinfo' } ... - { 'style', 'text', 'tag', 'val12', 'string', ' ', 'userdata', 'datinfo' } {} }; - supergui(gcf, geometry, [], listui{:}); - geometry = { [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] }; - listui = { { } ... - { } ... - { 'style', 'text', 'tag', 'mainwin1', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin2', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin3', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin4', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin5', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin6', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin7', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin8', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin9', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin10', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin11', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin12', 'string', ' ', 'userdata', 'fullline' } ... - { 'style', 'text', 'tag', 'mainwin13', 'string', ' ', 'userdata', 'fullline' } {} }; - supergui(gcf, geometry, [], listui{:}); - - titleh = findobj('parent', gcf, 'tag', 'win0'); - alltexth = findobj('parent', gcf, 'style', 'text'); - alltexth = setdiff_bc(alltexth, titleh); - - set(gcf, 'Position',[200 100 (WINMINX+WINMAXX+2*BORDERINT+2*BORDEREXT) (WINY+2*BORDERINT+2*BORDEREXT) ]); - set(titleh, 'fontsize', TEXT_FONTSIZE_L, 'fontweight', 'bold'); - set(alltexth, 'fontname', FONTNAME, 'fontsize', FONTSIZE); - set(W_MAIN, 'visible', 'on'); -end; - +catch, end + +BackgroundColor = get(gcf, 'color'); %[0.701960784313725 0.701960784313725 0.701960784313725]; +H_MAIN(1) = uicontrol('Parent',W_MAIN, ... + 'Units','points', ... + 'BackgroundColor',COLOR, ... + 'ListboxTop',0, ... + 'HorizontalAlignment', 'left',... + 'Position',[BORDEREXT BORDEREXT (WINMINX+WINMAXX+2*BORDERINT) (WINY)], ... + 'Style','frame', ... + 'Tag','Frame1'); +set(H_MAIN(1), 'unit', 'normalized'); +geometry = { [1] [1] [1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1 1] [1] }; +listui = { { 'style', 'text', 'string', 'Parameters of the current set', 'tag', 'win0' } { } ... + { 'style', 'text', 'tag', 'win1', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win2', 'string', 'Channels per frame', 'userdata', 'datinfo'} ... + { 'style', 'text', 'tag', 'val2', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win3', 'string', 'Frames per epoch', 'userdata', 'datinfo'} ... + { 'style', 'text', 'tag', 'val3', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win4', 'string', 'Epochs', 'userdata', 'datinfo'} ... + { 'style', 'text', 'tag', 'val4', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win5', 'string', 'Events', 'userdata', 'datinfo'} ... + { 'style', 'text', 'tag', 'val5', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win6', 'string', 'Sampling rate (Hz)', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'val6', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win7', 'string', 'Epoch start (sec)', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'val7', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win8', 'string', 'Epoch end (sec)', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'val8', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win9', 'string', 'Average reference', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'val9', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win10', 'string', 'Channel locations', 'userdata', 'datinfo'} ... + { 'style', 'text', 'tag', 'val10', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win11', 'string', 'ICA weights', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'val11', 'string', ' ', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'win12', 'string', 'Dataset size (Mb)', 'userdata', 'datinfo' } ... + { 'style', 'text', 'tag', 'val12', 'string', ' ', 'userdata', 'datinfo' } {} }; +supergui(gcf, geometry, [], listui{:}); +geometry = { [1] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1 0.01] [1] }; +listui = { { } ... + { 'style', 'text', 'tag', 'mainwin0', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin1', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin2', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin3', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin4', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin5', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin6', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin7', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin8', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin9', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin10', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin11', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin12', 'string', ' ', 'userdata', 'fullline' } { } ... + { 'style', 'text', 'tag', 'mainwin13', 'string', ' ', 'userdata', 'fullline' } { } {} }; +firstElemHeight = 1; +if ispc, firstElemHeight = 1.7; end +supergui(gcf, geometry, [firstElemHeight 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1], listui{:}); + +titleh = findobj('parent', gcf, 'tag', 'win0'); +alltexth = findobj('parent', gcf, 'style', 'text'); +alltexth = setdiff_bc(alltexth, titleh); + +set(gcf, 'Position',[200 100 (WINMINX+WINMAXX+2*BORDERINT+2*BORDEREXT) (WINY+2*BORDERINT+2*BORDEREXT) ]); +set(titleh, 'fontsize', TEXT_FONTSIZE_L, 'fontweight', 'bold'); +set(alltexth, 'fontname', FONTNAME, 'fontsize', FONTSIZE); + +set(W_MAIN, 'visible', 'on'); + return; -% eeglab(''redraw'')() - Update EEGLAB menus based on values of global variables. -% -% Usage: >> eeglab(''redraw'')( ); -% -% Author: Arnaud Delorme, CNL / Salk Institute, 2001 -% -% See also: eeg_global(), eeglab() - -% WHEN THIS FUNCTION WAS SEPARATED -% Revision 1.21 2002/04/23 19:09:25 arno -% adding automatic dataset search -% Revision 1.20 2002/04/18 20:02:23 arno -% retrIeve -% Revision 1.18 2002/04/18 16:28:28 scott -% EEG.averef printed as 'Yes' or 'No' -sm -% Revision 1.16 2002/04/18 16:03:15 scott -% editted "Events/epoch info (nb) -> Events -sm -% Revision 1.14 2002/04/18 14:46:58 scott -% editted main window help msg -sm -% Revision 1.10 2002/04/18 03:02:17 scott -% edited opening instructions -sm -% Revision 1.9 2002/04/11 18:23:33 arno -% Oups, typo which crashed EEGLAB -% Revision 1.8 2002/04/11 18:07:59 arno -% adding average reference variable -% Revision 1.7 2002/04/11 17:49:40 arno -% corrected operator precedence problem -% Revision 1.6 2002/04/11 15:36:55 scott -% added parentheses to final ( - & - ), line 84. ARNO PLEASE CHECK -sm -% Revision 1.5 2002/04/11 15:34:50 scott -% put isempty(CURRENTSET) first in line ~80 -sm -% Revision 1.4 2002/04/11 15:31:47 scott -% added test isempty(CURRENTSET) line 78 -sm -% Revision 1.3 2002/04/11 01:41:27 arno -% checking dataset ... and inteligent menu update -% Revision 1.2 2002/04/09 20:47:41 arno -% introducing event number into gui - -function updatemenu(); +% Update EEGLAB GUI (list of datasets) +% ----------------- +function updatemenu() eeg_global; W_MAIN = findobj('tag', 'EEGLAB'); EEGUSERDAT = get(W_MAIN, 'userdata'); H_MAIN = EEGUSERDAT{1}; EEGMENU = EEGUSERDAT{2}; -if length(EEGUSERDAT) > 2 - tb = EEGUSERDAT{3}; -else tb = []; -end; -if ~isempty(tb) && ~isstr(tb) - eval('tb.RefreshToolbar();'); -end; -if exist('CURRENTSET') ~= 1, CURRENTSET = 0; end; -if isempty(ALLEEG), ALLEEG = []; end; -if isempty(EEG), EEG = []; end; +if exist('CURRENTSET') ~= 1, CURRENTSET = 0; end +if isempty(ALLEEG), ALLEEG = []; end +if isempty(EEG), EEG = []; end % test if the menu is present try figure(W_MAIN); set_m = findobj( 'parent', W_MAIN, 'Label', 'Datasets'); -catch, return; end; +catch, return; end index = 1; indexmenu = 1; -MAX_SET = max(length( ALLEEG ), length(EEGMENU)-1); +% check if EEG has changed +% ------------------------ tmp = warning; warning off; clear functions; warning(tmp); eeglab_options; -if isempty(ALLEEG) && ~isempty(EEG) && ~isempty(EEG.data) +if isempty(ALLEEG) && ~isempty(EEG) && all(arrayfun(@(eeg) ~isempty(eeg.data), EEG)) ALLEEG = EEG; -end; +else + % check dataset + if ~isempty(EEG) && ~isempty(ALLEEG) && ~isequaln(EEG, ALLEEG(CURRENTSET)) + if length(EEG) > 1 + options = { 'EEG overwrites ALLEEG', 'ALLEEG overwrites EEG', 'Do nothing' }; + res = questdlg2('In a STUDY, ALLEEG and EEG should be equal and they are not. How do you want EEGLAB to resolve this?', 'ALLEEG and EEG structure do not match', options{:}, options{1}); + if isequal(res, options{1}) + disp('Overwriting ALLEEG with EEG') + ALLEEG = EEG; + elseif isequal(res, options{2}) + disp('Overwriting EEG with ALLEEG') + EEG = ALLEEG; + end + else + EEG.saved = 'no'; + [ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, 'study', ~isempty(STUDY)+0, 'guistring', 'The EEG structure has changed, what do you want to do?'); + end + end +end + +% Maximum number of set +% --------------------- +MAX_SET = max(length( ALLEEG ), length(EEGMENU)-1); +if MAX_SET > 200 + disp('Updating menu, allowing selection of the first 200 datasets only to speed up display...') + MAX_SET = 200; +end % setting the dataset menu % ------------------------ while( index <= MAX_SET) try set( EEGMENU(index), 'Label', '------', 'checked', 'off'); - catch, + catch if mod(index, 30) == 0 tag = [ 'More (' int2str(index/30) ') ->' ]; tmp_m = findobj('label', tag); if isempty(tmp_m) - set_m = uimenu( set_m, 'Label', tag, 'userdata', 'study:on'); + set_m = eegmenu( false, set_m, 'Label', tag, 'userdata', 'study:on'); else set_m = tmp_m; - end; - end; + end + end try set( EEGMENU(index), 'Label', '------', 'checked', 'off'); - catch, EEGMENU(index) = uimenu( set_m, 'Label', '------', 'Enable', 'on'); end; - end; + catch, EEGMENU(index) = eegmenu( false, set_m, 'Label', '------', 'Enable', 'on'); end + end set( EEGMENU(index), 'Enable', 'on', 'separator', 'off' ); try, ALLEEG(index).data; if ~isempty( ALLEEG(index).data) cb_retrieve = [ '[ALLEEG EEG CURRENTSET LASTCOM] = pop_newset(ALLEEG, EEG, CURRENTSET, ''retrieve'', ' int2str(index) ', ''study'', ~isempty(STUDY)+0);' ... - 'if CURRENTSTUDY & ~isempty(LASTCOM), CURRENTSTUDY = 0; LASTCOM = [ ''CURRENTSTUDY = 0;'' LASTCOM ]; end; eegh(LASTCOM);' ... + 'if CURRENTSTUDY && ~isempty(LASTCOM), CURRENTSTUDY = 0; LASTCOM = [ ''CURRENTSTUDY = 0;'' LASTCOM ]; end; eegh(LASTCOM);' ... 'eeglab(''redraw'');' ]; menutitle = sprintf('Dataset %d:%s', index, ALLEEG(index).setname); set( EEGMENU(index), 'Label', menutitle, 'userdata', 'study:on'); set( EEGMENU(index), 'CallBack', cb_retrieve ); set( EEGMENU(index), 'Enable', 'on' ); - if any(index == CURRENTSET), set( EEGMENU(index), 'checked', 'on' ); end; - end; - catch, end; + if any(index == CURRENTSET), set( EEGMENU(index), 'checked', 'on' ); end + end + catch, end index = index+1; -end; +end hh = findobj( 'parent', set_m, 'Label', '------'); set(hh, 'Enable', 'off'); @@ -1472,16 +1512,16 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD ' eeglab(''redraw'');' ... 'end;' ... 'clear tmpind nonempty;' ]; - if MAX_SET == length(EEGMENU), EEGMENU(end+1) = uimenu( set_m, 'Label', '------', 'Enable', 'on'); end; + if MAX_SET == length(EEGMENU), EEGMENU(end+1) = eegmenu( false, set_m, 'Label', '------', 'Enable', 'on'); end set(EEGMENU(end), 'enable', 'on', 'Label', 'Select multiple datasets', ... 'callback', cb_select, 'separator', 'on', 'userdata', 'study:on'); -end; +end % STUDY consistency % ----------------- exist_study = 0; -if exist('STUDY') & exist('CURRENTSTUDY') +if exist('STUDY') && exist('CURRENTSTUDY') % if study present, check study consistency with loaded datasets % -------------------------------------------------------------- @@ -1499,21 +1539,21 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD pop_savestudy(STUDY, ALLEEG); STUDY = []; CURRENTSTUDY = 0; - end; + end else warndlg2( strvcat('The study was not compatible any more with the datasets present in memory.', ... 'Since it had not changed since last saved, it was simply removed from', ... 'memory.') ); STUDY = []; CURRENTSTUDY = 0; - end; - end; - end; + end + end + end if ~isempty(STUDY) exist_study = 1; - end; -end; + end +end % menu for selecting STUDY set % ---------------------------- @@ -1524,76 +1564,76 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD 'eeglab(''redraw'');' ]; tmp_m = findobj('label', 'Select the study set'); delete(tmp_m); % in case it is not at the end - tmp_m = uimenu( set_m, 'Label', 'Select the study set', 'Enable', 'on', 'userdata', 'study:on'); + tmp_m = eegmenu( false, set_m, 'Label', 'Select the study set', 'Enable', 'on', 'userdata', 'study:on'); set(tmp_m, 'enable', 'on', 'callback', cb_select, 'separator', 'on'); else delete( findobj('label', 'Select the study set') ); -end; +end EEGUSERDAT{2} = EEGMENU; set(W_MAIN, 'userdata', EEGUSERDAT); -if (isempty(CURRENTSET) | length(ALLEEG) < CURRENTSET(1) | CURRENTSET(1) == 0 | isempty(ALLEEG(CURRENTSET(1)).data)) +if (isempty(CURRENTSET) || length(ALLEEG) < CURRENTSET(1) || CURRENTSET(1) == 0 || isempty(ALLEEG(CURRENTSET(1)).data)) CURRENTSET = 0; for index = 1:length(ALLEEG) if ~isempty(ALLEEG(index).data) CURRENTSET = index; break; - end; - end; + end + end if CURRENTSET ~= 0 eegh([ '[EEG ALLEEG CURRENTSET] = eeg_retrieve(ALLEEG,' int2str(CURRENTSET) ');' ]) - [EEG ALLEEG] = eeg_retrieve(ALLEEG, CURRENTSET); + [EEG, ALLEEG] = eeg_retrieve(ALLEEG, CURRENTSET); else EEG = eeg_emptyset; - end; -end; + end +end -if (isempty(EEG) | isempty(EEG(1).data)) & CURRENTSET(1) ~= 0 +if (isempty(EEG) || isempty(EEG(1).data)) && CURRENTSET(1) ~= 0 eegh([ '[EEG ALLEEG CURRENTSET] = eeg_retrieve(ALLEEG,' int2str(CURRENTSET) ');' ]) - [EEG ALLEEG] = eeg_retrieve(ALLEEG, CURRENTSET); -end; + [EEG, ALLEEG] = eeg_retrieve(ALLEEG, CURRENTSET); +end % test if dataset has changed % --------------------------- -if length(EEG) == 1 - if ~isempty(ALLEEG) & CURRENTSET~= 0 & ~isequal(EEG.data, ALLEEG(CURRENTSET).data) & ~isnan(EEG.data(1)) - % the above comparison does not work for ome structures - %tmpanswer = questdlg2(strvcat('The current EEG dataset has changed. What should eeglab do with the changes?', ' '), ... - % 'Dataset change detected', ... - % 'Keep changes', 'Delete changes', 'New dataset', 'Make new dataset'); - disp('Warning: for some reason, the backup dataset in EEGLAB memory does not'); - disp(' match the current dataset. The dataset in memory has been overwritten'); - [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); - eegh('[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);'); - - %if tmpanswer(1) == 'D' % delete changes - % [EEG ALLEEG] = eeg_retrieve(ALLEEG, CURRENTSET); - % eegh('[EEG ALLEEG] = eeg_retrieve( ALLEEG, CURRENTSET);'); - %elseif tmpanswer(1) == 'K' % keep changes - % [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); - % eegh('[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);'); - %else % make new dataset - % [ALLEEG EEG CURRENTSET LASTCOM] = pop_newset(ALLEEG, EEG, CURRENTSET); - % eegh(LASTCOM); - % MAX_SET = max(length( ALLEEG ), length(EEGMENU)); - %end; - end; -end; +if length(EEG) == 1 && length(CURRENTSET) == 1 + if ~isempty(ALLEEG) && CURRENTSET~= 0 && ~isequal(EEG.data, ALLEEG(CURRENTSET).data) + if exist('isequaln','builtin') ~= 5, isequalfunc = @isequal; else isequalfunc = @isequaln; end + if isequalfunc(EEG.data, ALLEEG(CURRENTSET).data) + disp('Warning: Your data contains NaNs.'); + else + disp('Warning: The backup dataset in EEGLAB memory does not match the current dataset.'); + disp(' The dataset in memory has been overwritten'); + [ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); + eegh('[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);'); + end + end +else + EEG = ALLEEG(CURRENTSET); +end % print some information on the main figure % ------------------------------------------ g = myguihandles(gcf); if ~isfield(g, 'win0') % no display return; -end; +end study_selected = 0; -if exist('STUDY') & exist('CURRENTSTUDY') - if CURRENTSTUDY == 1, study_selected = 1; end; -end; +if exist('STUDY') && exist('CURRENTSTUDY') + if CURRENTSTUDY == 1, study_selected = 1; end +end menustatus = {}; +try + curroiFlag = unique(cellfun(@(x)getfield(x, 'eeglab_using_roi'), { EEG(:).roi })); + if length(curroiFlag) == 1 && curroiFlag + menustatus = { menustatus{:} 'roi_connect' }; + else + disp('Warning: different settings for using ROIs detected in different datasets'); + end +catch +end if study_selected menustatus = { menustatus{:} 'study' }; @@ -1607,10 +1647,10 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD % dataset type % ------------ datasettype = unique_bc( [ EEG.trials ] ); - if datasettype(1) == 1 & length(datasettype) == 1, datasettype = 'continuous'; + if datasettype(1) == 1 && length(datasettype) == 1, datasettype = 'continuous'; elseif datasettype(1) == 1, datasettype = 'epoched and continuous'; else datasettype = 'epoched'; - end; + end % number of channels and channel locations % ---------------------------------------- @@ -1620,7 +1660,7 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD if length(anyempty) == 2, chanlocs = 'mixed, yes and no'; elseif anyempty == 0, chanlocs = 'yes'; else chanlocs = 'no'; - end; + end % ica weights % ----------- @@ -1628,17 +1668,17 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD if length(anyempty) == 2, studystatus = 'Missing ICA dec.'; elseif anyempty == 0, studystatus = 'Ready to precluster'; else studystatus = 'Missing ICA dec.'; - end; + end - % consistency & other parameters + % consistency && other parameters % ------------------------------ - [EEG epochconsist] = eeg_checkset(EEG, 'epochconsist'); % epoch consistency - [EEG chanconsist ] = eeg_checkset(EEG, 'chanconsist'); % channel consistency - [EEG icaconsist ] = eeg_checkset(EEG, 'icaconsist'); % ICA consistency + [EEG, epochconsist] = eeg_checkset(EEG, 'epochconsist'); % epoch consistency + [EEG, chanconsist ] = eeg_checkset(EEG, 'chanconsist'); % channel consistency + [EEG, icaconsist ] = eeg_checkset(EEG, 'icaconsist'); % ICA consistency totevents = num2str(sum( cellfun( 'length', { EEG.event }) )); % total number of events totsize = whos('STUDY', 'ALLEEG'); % total size - if isempty(STUDY.session), sessionstr = ''; else sessionstr = vararg2str(STUDY.session); end; - if isempty(STUDY.condition), condstr = ''; else condstr = vararg2str(STUDY.condition); end; + if isempty(STUDY.session), sessionstr = ''; else sessionstr = vararg2str(STUDY.session); end + if isempty(STUDY.condition), condstr = ''; else condstr = vararg2str(STUDY.condition); end % determine study status % ---------------------- @@ -1647,10 +1687,10 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD studystatus = 'Pre-clustered'; elseif length(STUDY.cluster) > 1 studystatus = 'Clustered'; - end; + end elseif length(STUDY.cluster) > 1 studystatus = 'Clustered'; - end; + end % text % ---- @@ -1673,7 +1713,7 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD set( g.win1, 'String', sprintf('Study filename: ...%s\n', fullfilename(max(1,length(fullfilename)-26):end) )); else set( g.win1, 'String', sprintf('Study filename: %s\n' , fullfilename)); - end; + end condconsist = std_checkconsist(STUDY, 'uniform', 'condition'); groupconsist = std_checkconsist(STUDY, 'uniform', 'group'); sessconsist = std_checkconsist(STUDY, 'uniform', 'session'); @@ -1685,14 +1725,14 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD set( g.val4, 'String', [ int2str(max(1, length(STUDY.condition))) txtcond ]); set( g.val5, 'String', [ int2str(max(1, length(STUDY.session))) txtsess ]); set( g.val6, 'String', [ int2str(max(1, length(STUDY.group))) txtgroup ]); - set( g.val7, 'String', epochconsist); - set( g.val8, 'String', chanlenstr); - set( g.val9, 'String', chanlocs); - set( g.val10, 'String', length(STUDY.cluster)); - set( g.val11, 'String', studystatus); + set( g.val7, 'String', char(epochconsist)); + set( g.val8, 'String', char(chanlenstr)); + set( g.val9, 'String', char(chanlocs)); + set( g.val10, 'String', num2str(length(STUDY.cluster))); + set( g.val11, 'String', char(studystatus)); set( g.val12, 'String', num2str(round(sum( [ totsize.bytes] )/1E6*10)/10)); -elseif (exist('EEG') == 1) & ~isnumeric(EEG) & ~isempty(EEG(1).data) +elseif (exist('EEG') == 1) && ~isnumeric(EEG) && ~isempty(EEG(1).data) hh = findobj('parent', gcf, 'userdata', 'fullline'); set(hh, 'visible', 'off'); hh = findobj('parent', gcf, 'userdata', 'datinfo'); set(hh, 'visible', 'on'); @@ -1706,17 +1746,17 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD strsetnum = 'Datasets '; for i = CURRENTSET strsetnum = [ strsetnum int2str(i) ',' ]; - end; + end strsetnum = strsetnum(1:end-1); set( g.win0, 'String', strsetnum); % dataset type % ------------ datasettype = unique_bc( [ EEG.trials ] ); - if datasettype(1) == 1 & length(datasettype) == 1, datasettype = 'continuous'; + if datasettype(1) == 1 && length(datasettype) == 1, datasettype = 'continuous'; elseif datasettype(1) == 1, datasettype = 'epoched and continuous'; else datasettype = 'epoched'; - end; + end % number of channels and channel locations % ---------------------------------------- @@ -1726,7 +1766,7 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD if length(anyempty) == 2, chanlocs = 'mixed, yes and no'; elseif anyempty == 0, chanlocs = 'yes'; else chanlocs = 'no'; - end; + end % ica weights % ----------- @@ -1734,13 +1774,13 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD if length(anyempty) == 2, icaweights = 'mixed, yes and no'; elseif anyempty == 0, icaweights = 'yes'; else icaweights = 'no'; - end; + end % consistency & other parameters % ------------------------------ - [EEG epochconsist] = eeg_checkset(EEG, 'epochconsist'); % epoch consistency - [EEG chanconsist ] = eeg_checkset(EEG, 'chanconsist'); % channel consistency - [EEG icaconsist ] = eeg_checkset(EEG, 'icaconsist'); % ICA consistency + [EEG, epochconsist] = eeg_checkset(EEG, 'epochconsist'); % epoch consistency + [EEG, chanconsist ] = eeg_checkset(EEG, 'chanconsist'); % channel consistency + [EEG, icaconsist ] = eeg_checkset(EEG, 'icaconsist'); % ICA consistency totevents = num2str(sum( cellfun( 'length', { EEG.event }) )); % total number of events srate = vararg2str( mattocell( unique( [ EEG.srate ] ) )); % sampling rate totsize = whos('EEG'); % total size @@ -1763,18 +1803,18 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD % ------ set( g.win1, 'String', sprintf('Groupname: -(soon)-\n')); set( g.val2, 'String', int2str(length(EEG))); - set( g.val3, 'String', datasettype); - set( g.val4, 'String', epochconsist); - set( g.val5, 'String', chanlenstr); - set( g.val6, 'String', chanconsist); - set( g.val7, 'String', chanlocs); - set( g.val8, 'String', totevents); - set( g.val9, 'String', srate); - set( g.val10, 'String', icaweights); - set( g.val11, 'String', icaconsist); + set( g.val3, 'String', char(datasettype)); + set( g.val4, 'String', char(epochconsist)); + set( g.val5, 'String', char(chanlenstr)); + set( g.val6, 'String', char(chanconsist)); + set( g.val7, 'String', char(chanlocs)); + set( g.val8, 'String', char(totevents)); + set( g.val9, 'String', char(srate)); + set( g.val10, 'String', char(icaweights)); + set( g.val11, 'String', char(icaconsist)); set( g.val12, 'String', num2str(round(totsize.bytes/1E6*10)/10)); - else % one continous dataset selected + else % one continuous dataset selected menustatus = { menustatus{:} 'continuous_dataset' }; @@ -1794,16 +1834,16 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD if CURRENTSET == 0, strsetnum = ''; else strsetnum = ['#' int2str(CURRENTSET) ': ']; - end; + end maxchar = 28; if ~isempty( EEG.setname ) if length(EEG.setname) > maxchar+2 set( g.win0, 'String', [strsetnum EEG.setname(1:min(maxchar,length(EEG.setname))) '...' ]); else set( g.win0, 'String', [strsetnum EEG.setname ]); - end; + end else set( g.win0, 'String', [strsetnum '(no dataset name)' ] ); - end; + end fullfilename = fullfile(EEG.filepath, EEG.filename); if ~isempty(fullfilename) @@ -1811,47 +1851,47 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD set( g.win1, 'String', sprintf('Filename: ...%s\n', fullfilename(max(1,length(fullfilename)-26):end) )); else set( g.win1, 'String', sprintf('Filename: %s\n', fullfilename)); - end; + end else set( g.win1, 'String', sprintf('Filename: none\n')); - end; + end set( g.val2, 'String', int2str(fastif(isempty(EEG.data), 0, size(EEG.data,1)))); set( g.val3, 'String', int2str(EEG.pnts)); set( g.val4, 'String', int2str(EEG.trials)); set( g.val5, 'String', fastif(isempty(EEG.event), 'none', int2str(length(EEG.event)))); set( g.val6, 'String', int2str( round(EEG.srate)) ); - if round(EEG.xmin) == EEG.xmin & round(EEG.xmax) == EEG.xmax + if round(EEG.xmin) == EEG.xmin && round(EEG.xmax) == EEG.xmax set( g.val7, 'String', sprintf('%d\n', EEG.xmin)); set( g.val8, 'String', sprintf('%d\n', EEG.xmax)); else set( g.val7, 'String', sprintf('%6.3f\n', EEG.xmin)); set( g.val8, 'String', sprintf('%6.3f\n', EEG.xmax)); - end; + end % reference if isfield(EEG(1).chanlocs, 'ref') - [curref tmp allinds] = unique_bc( { EEG(1).chanlocs.ref }); + [curref, ~, allinds] = unique_bc( { EEG(1).chanlocs.ref }); maxind = 1; for ind = unique_bc(allinds) if length(find(allinds == ind)) > length(find(allinds == maxind)) maxind = ind; - end; - end; + end + end curref = curref{maxind}; - if isempty(curref), curref = 'unknown'; end; + if isempty(curref), curref = 'unknown'; end else curref = 'unknown'; - end; + end set( g.val9, 'String', curref); if isempty(EEG.chanlocs) set( g.val10, 'String', 'No'); else - if ~isfield(EEG.chanlocs, 'theta') | all(cellfun('isempty', { EEG.chanlocs.theta })) + if ~isfield(EEG.chanlocs, 'theta') || all(cellfun('isempty', { EEG.chanlocs.theta })) set( g.val10, 'String', 'No (labels only)'); else set( g.val10, 'String', 'Yes'); - end; - end; + end + end set( g.val11, 'String', fastif(isempty(EEG.icasphere), 'No', 'Yes')); tmp = whos('EEG'); @@ -1859,7 +1899,7 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD set( g.val12, 'String', num2str(round(tmp.bytes/1E6*10)/10)); else set( g.val12, 'String', [ num2str(round(tmp.bytes/1E6*10)/10) ' (file mapped)' ]); - end; + end if EEG.trials > 1 || EEG.xmin ~= 0 menustatus = { menustatus{:} 'epoched_dataset' }; @@ -1868,36 +1908,45 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD end if ~isfield(EEG.chanlocs, 'theta') menustatus = { menustatus{:} 'chanloc_absent' }; - end; + end if isempty(EEG.icaweights) menustatus = { menustatus{:} 'ica_absent' }; - end; - end; + end + end else - menustatus = { menustatus{:} 'startup' }; + menustatus = { 'startup' }; hh = findobj('parent', gcf, 'userdata', 'fullline'); set(hh, 'visible', 'on'); hh = findobj('parent', gcf, 'userdata', 'datinfo'); set(hh, 'visible', 'off'); set( g.win0, 'String', 'No current dataset'); + set( g.mainwin0, 'String', 'Suggested steps to get started', 'fontweight', 'bold'); set( g.mainwin1, 'String', '- Create a new or load an existing dataset:'); set( g.mainwin2, 'String', ' Use "File > Import data" (new)'); - set( g.mainwin3, 'String', ' Or "File > Load existing dataset" (old)'); - set( g.mainwin4, 'String', '- If new,'); - set( g.mainwin5, 'String', ' "File > Import epoch info" (data epochs) else'); - set( g.mainwin6, 'String', ' "File > Import event info" (continuous data)'); - set( g.mainwin7, 'String', ' "Edit > Dataset info" (add/edit dataset info)'); - set( g.mainwin8, 'String', ' "File > Save dataset" (save dataset)'); - set( g.mainwin9, 'String', '- Prune data: "Edit > Select data"'); - set( g.mainwin10,'String', '- Reject data: "Tools > Reject continuous data"'); - set( g.mainwin11,'String', '- Epoch data: "Tools > Extract epochs"'); - set( g.mainwin12,'String', '- Remove baseline: "Tools > Remove baseline"'); - set( g.mainwin13,'String', '- Run ICA: "Tools > Run ICA"'); -end; + set( g.mainwin3, 'String', ' Or "File > Load existing dataset" (load)'); + set( g.mainwin4, 'String', ' (find tutorial data in sample_data folder)'); + set( g.mainwin5, 'String', '- If newly imported raw dataset'); + set( g.mainwin6, 'String', ' "Edit > Channel locations" (look up locations)'); + set( g.mainwin7, 'String', ' "File > Import event info" (for continuous data)'); + set( g.mainwin8, 'String', '- Filter data: "Tools > Filter data"'); + set( g.mainwin9, 'String', '- Reject data: "Tools > Reject data by eye"'); + set( g.mainwin10,'String', '- Run ICA: "Tools > Run ICA" (can take time)'); + set( g.mainwin11,'String', '- Reject by ICA: "Tools > Reject data using ICA"'); + set( g.mainwin12,'String', '- Epoch data: "Tools > Extract epochs"'); + set( g.mainwin13,'String', '- Plot ERP: "Plot > Channel ERP > In scalp array"'); +end % ERPLAB if exist('ALLERP') == 1 && ~isempty(ALLERP) menustatus = { menustatus{:} 'erp_dataset' }; -end; +end + +if exist('ALLBEST') == 1 && ~isempty(ALLBEST) + menustatus = { menustatus{:} 'best_dataset' }; +end + +if exist('ALLMVPC') == 1 && ~isempty(ALLMVPC) + menustatus = { menustatus{:} 'mvpc_dataset'}; +end % enable selected menu items % -------------------------- @@ -1938,20 +1987,30 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD set(allmenus(indmatchvar), 'enable', 'off'); -end; +end if any(strcmp(menustatus, 'chanloc_absent')) eval('indmatchvar = cellfun(@(x)(~isempty(findstr(num2str(x), ''chanloc:on''))), allstrs);'); set(allmenus(indmatchvar), 'enable', 'off'); -end; +end if any(strcmp(menustatus, 'ica_absent')) eval('indmatchvar = cellfun(@(x)(~isempty(findstr(num2str(x), ''ica:on''))), allstrs);'); set(allmenus(indmatchvar), 'enable', 'off'); -end; +end +if any(strcmp(menustatus, 'roi_connect')) + + eval('indmatchvar = cellfun(@(x)(~isempty(findstr(num2str(x), ''roi:off''))), allstrs);'); + set(allmenus(indmatchvar), 'enable', 'off'); + +end +% always off +eval('indmatchvar = cellfun(@(x)(~isempty(findstr(num2str(x), ''enable:off''))), allstrs);'); +set(allmenus(indmatchvar), 'enable', 'off'); + % -------------------------------- % Javier Lopez-Calderon for ERPLAB if any(strcmp(menustatus, 'erp_dataset')) @@ -1960,6 +2019,20 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD end % end, Javier Lopez-Calderon for ERPLAB % -------------------------------- +% -------------------------------- +% Aaron Matthew Simmons for ERPLAB + +if any(strcmp(menustatus, 'best_dataset')) + set(allmenus, 'enable', 'on'); + eval('indmatchvar = cellfun(@(x)(~isempty(findstr(num2str(x), ''bestset:off''))), allstrs);'); + set(allmenus(indmatchvar), 'enable', 'off'); +end +if any(strcmp(menustatus, 'mvpc_dataset')) + set(allmenus, 'enable', 'on'); + eval('indmatchvar = cellfun(@(x)(~isempty(findstr(num2str(x), ''mvpcset:off''))), allstrs);'); + set(allmenus(indmatchvar), 'enable', 'off'); +end +% end, Aaron Matthew Simmons for ERPLAB % adjust title extent @@ -1970,15 +2043,16 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD % adjust all font sizes (RMC fix MATLAB 2014 compatibility) % ------------------- -handlesname = fieldnames(g); -for i = 1:length(handlesname) - if isprop(eval(['g.' handlesname{i}]),'Style') & ~strcmp(handlesname{i},'win0') - propval = get(eval(['g.' handlesname{i}]), 'Style'); - if strcmp(propval,'text') - set(eval(['g.' handlesname{i}]),'FontSize',TEXT_FONTSIZE); - end - end -end +% icadefs; +% handlesname = fieldnames(g); +% for i = 1:length(handlesname) +% if isprop(eval(['g.' handlesname{i}]),'Style') && ~strcmp(handlesname{i},'win0') +% propval = get(eval(['g.' handlesname{i}]), 'Style'); +% if strcmp(propval,'text') +% set(eval(['g.' handlesname{i}]),'FontSize',TEXT_FONTSIZE); +% end +% end +% end return; @@ -1988,7 +2062,7 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD switch lower(ButtonName), case 'cancel', num = 0; case 'yes', num = 1; - end; + end function g = myguihandles(fig) g = []; @@ -1996,116 +2070,118 @@ function command_on_update_menu_click(callerHandle, tmp, eeglabUpdater, installD for index = 1:length(hh) if ~isempty(get(hh(index), 'tag')) g = setfield(g, get(hh(index), 'tag'), hh(index)); - end; - end; + end + end -function rmpathifpresent(newpath); +function rmpathifpresent(newpath) comp = computer; if strcmpi(comp(1:2), 'PC') newpath = [ newpath ';' ]; else newpath = [ newpath ':' ]; - end; - if ismatlab - p = matlabpath; - else p = path; - end; + end + p = path; ind = strfind(p, newpath); if ~isempty(ind) rmpath(newpath); - end; + end % add path only if it is not already in the list % ---------------------------------------------- -function addpathifnotinlist(newpath); +function addpathifnotinlist(newpath) comp = computer; if strcmpi(comp(1:2), 'PC') newpathtest = [ newpath ';' ]; else newpathtest = [ newpath ':' ]; - end; - if ismatlab - p = matlabpath; - else p = path; - end; + end + p = path; ind = strfind(p, newpathtest); if isempty(ind) if exist(newpath) == 7 addpath(newpath); - end; - end; + end + end -function addpathifnotexist(newpath, functionname); +function addpathifnotexist(newpath, functionname) tmpp = mywhich(functionname); if isempty(tmpp) addpath(newpath); - end; + end % find a function path and add path if not present % ------------------------------------------------ -function myaddpath(eeglabpath, functionname, pathtoadd); +function myaddpath(eeglabpath, functionname, pathtoadd) tmpp = mywhich(functionname); tmpnewpath = [ eeglabpath pathtoadd ]; if ~isempty(tmpp) tmpp = tmpp(1:end-length(functionname)); - if length(tmpp) > length(tmpnewpath), tmpp = tmpp(1:end-1); end; % remove trailing filesep - if length(tmpp) > length(tmpnewpath), tmpp = tmpp(1:end-1); end; % remove trailing filesep - %disp([ tmpp ' | ' tmpnewpath '(' num2str(~strcmpi(tmpnewpath, tmpp)) ')' ]); + if length(tmpp) > length(tmpnewpath), tmpp = tmpp(1:end-1); end % remove trailing filesep + if length(tmpp) > length(tmpnewpath), tmpp = tmpp(1:end-1); end % remove trailing filesep + %disp([ tmpp ' || ' tmpnewpath '(' num2str(~strcmpi(tmpnewpath, tmpp)) ')' ]); if ~strcmpi(tmpnewpath, tmpp) warning('off', 'MATLAB:dispatcher:nameConflict'); addpath(tmpnewpath); warning('on', 'MATLAB:dispatcher:nameConflict'); - end; + end else %disp([ 'Adding new path ' tmpnewpath ]); addpathifnotinlist(tmpnewpath); - end; - -function val = iseeglabdeployed2; -%val = 1; return; -if exist('isdeployed') - val = isdeployed; -else val = 0; -end; - -function buildhelpmenu; + end % parse plugin function name % -------------------------- -function [name, vers] = parsepluginname(dirName); +function [name, vers] = parsepluginname(dirName, funcname) ind = find( dirName >= '0' & dirName <= '9' ); if isempty(ind) name = dirName; vers = ''; else ind = length(dirName); - while ind > 0 && ((dirName(ind) >= '0' & dirName(ind) <= '9') || dirName(ind) == '.' || dirName(ind) == '_') + while ind > 0 && ((dirName(ind) >= '0' && dirName(ind) <= '9') || dirName(ind) == '.' || dirName(ind) == '_') ind = ind - 1; - end; + end name = dirName(1:ind); vers = dirName(ind+1:end); - vers(find(vers == '_')) = '.'; - end; - + vers(vers == '_') = '.'; + if ~isempty(vers) + if vers(1) == '.', vers(1) = []; end + end + end + + % check with function name and change version if necessary (for loadhdf5) + if nargin > 1 && ~isempty(strfind(dirName, funcname)) + name1 = funcname; + vers2 = dirName(length(funcname)+1:end); + if ~isempty(vers2) + vers2(vers2 == '_') = '.'; + if ~isequal(vers, vers2) ... % differebt versions + && (vers2(1) >= '0' && vers2(1) <= '9') % version 2 is numerical + vers = vers2; + end + end + end + % required here because path not added yet % to the admin folder -function res = ismatlab; +function res = ismatlab -v = version; -if v(1) > '4' - res = 1; -else - res = 0; -end; +res = exist('OCTAVE_VERSION', 'builtin') == 0; -function res = mywhich(varargin); +function res = mywhich(varargin) try res = which(varargin{:}); catch - fprintf('Warning: permission error accesssing %s\n', varargin{1}); -end; - \ No newline at end of file + fprintf('Warning: permission error accessing %s\n', varargin{1}); +end + +function h = eegmenu( versL, varargin) + h = []; + if ~versL + h = uimenu(varargin{:}); + end + diff --git a/eeglab.prj b/eeglab.prj new file mode 100644 index 000000000..5bc802061 --- /dev/null +++ b/eeglab.prj @@ -0,0 +1,225 @@ + + + EEGLAB + + + 2021.1 + Arnaud Delorme and Scott Makeig + eeglab@sccn.ucsd.edu + + EEGLAB Matlab toolbox for processing continuous and event-related EEG, MEG and other electrophysiological data + EEGLAB is an interactive Matlab toolbox for processing continuous and event-related EEG, MEG and other electrophysiological data incorporating independent component analysis (ICA), time/frequency analysis, artifact rejection, event-related statistics, and several useful modes of visualization of the averaged and single-trial data. + ${PROJECT_ROOT}\functions\supportfiles\EEGLAB_compile_splash.jpg + + \EEGLAB\ + option.installpath.programfiles + + In the following directions, replace MCR_ROOT by the directory where the MATLAB Runtime is installed on the target machine. + +If the environment variable DYLD_LIBRARY_PATH is undefined, set it to the concatenation of the following strings: + + MCR_ROOT/v92/runtime/maci64: + MCR_ROOT/v92/sys/os/maci64: + MCR_ROOT/v92/bin/maci64 + +If it is defined, set it to the concatenation of these strings: + + ${LD_LIBRARY_PATH}: + MCR_ROOT/v92/runtime/maci64: + MCR_ROOT/v92/sys/os/maci64: + MCR_ROOT/v92/bin/maci64 + + ${PROJECT_ROOT}\eeglab\for_testing + ${PROJECT_ROOT}\eeglab\for_redistribution_files_only + ${PROJECT_ROOT}\eeglab\for_redistribution + ${PROJECT_ROOT}\eeglab + false + + subtarget.standalone + + true + false + false + MyAppInstaller_web + MyAppInstaller_mcr + MyAppInstaller_app + false + true + eeglab_log.txt + false + false + + Syntax + eeglab -? + eeglab onearg + Input Arguments + -? print help on how to use the application + onearg input arguments + Description + EEGLAB is an interactive Matlab toolbox for processing continuous and event-related EEG, MEG and other electrophysiological data incorporating independent component analysis (ICA), time/frequency analysis, artifact rejection, event-related statistics, and several useful modes of visualization of the averaged and single-trial data. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${PROJECT_ROOT}\eeglab.m + + + ${PROJECT_ROOT}\functions\adminfunc + ${PROJECT_ROOT}\functions\guifunc + ${PROJECT_ROOT}\functions\miscfunc + ${PROJECT_ROOT}\functions\popfunc + ${PROJECT_ROOT}\functions\sigprocfunc + ${PROJECT_ROOT}\functions\statistics + ${PROJECT_ROOT}\functions\studyfunc + ${PROJECT_ROOT}\functions\supportfiles + ${PROJECT_ROOT}\functions\timefreqfunc + ${PROJECT_ROOT}\plugins\Fieldtrip-lite220210 + ${PROJECT_ROOT}\plugins\Fieldtrip-lite220210\external\biosig + ${PROJECT_ROOT}\plugins\Fieldtrip-lite220210\forward + ${PROJECT_ROOT}\plugins\Fieldtrip-lite220210\inverse + ${PROJECT_ROOT}\plugins\Fieldtrip-lite220210\preproc + ${PROJECT_ROOT}\plugins\Fieldtrip-lite220210\statfun + ${PROJECT_ROOT}\plugins\Fieldtrip-lite220210\trialfun + ${PROJECT_ROOT}\plugins\Fileio220210 + ${PROJECT_ROOT}\plugins\ANTeepimport1.13 + ${PROJECT_ROOT}\plugins\ICLabel + ${PROJECT_ROOT}\plugins\MFFMatlabIO4.1 + ${PROJECT_ROOT}\plugins\MFFMatlabIO4.1\MFF-1.2.2-jar-with-dependencies.jar + ${PROJECT_ROOT}\plugins\PICARD1.0 + ${PROJECT_ROOT}\plugins\VisEd1.05 + ${PROJECT_ROOT}\plugins\bids-matlab-tools7.5 + ${PROJECT_ROOT}\plugins\bids-matlab-tools7.5\JSONIO + ${PROJECT_ROOT}\plugins\bva-io1.71 + ${PROJECT_ROOT}\plugins\clean_rawdata + ${PROJECT_ROOT}\plugins\dipfit + ${PROJECT_ROOT}\plugins\egilegacy1.0 + ${PROJECT_ROOT}\plugins\firfilt + ${PROJECT_ROOT}\plugins\iirfilt1.05 + ${PROJECT_ROOT}\plugins\musedirect1.2 + ${PROJECT_ROOT}\plugins\musemonitor4.0 + ${PROJECT_ROOT}\plugins\neuroscanio1.6 + ${PROJECT_ROOT}\plugins\scd1.0 + ${PROJECT_ROOT}\plugins\snapmaster1.0 + ${PROJECT_ROOT}\plugins\xdfimport1.18 + ${PROJECT_ROOT}\plugins\xdfimport1.18\xdf + + + ${PROJECT_ROOT}\README.md + ${PROJECT_ROOT}\eeglablicense.txt + ${PROJECT_ROOT}\functions\supportfiles\eeglab_run_this_one_on_osx_or_linux + ${PROJECT_ROOT}\functions\supportfiles\eeglab_run_this_one_on_windows.bat + ${PROJECT_ROOT}\sample_data + ${PROJECT_ROOT}\sample_locs + + + ${MATLAB_ROOT}\toolbox\local\restoredefaultpath.m + ${MATLAB_ROOT}\toolbox\local\userpath.m + ${MATLAB_ROOT}\toolbox\matlab\demos\watchoff.m + ${MATLAB_ROOT}\toolbox\matlab\demos\watchon.m + ${PROJECT_ROOT}\functions\@eegobj\display.m + ${PROJECT_ROOT}\functions\@eegobj\eegobj.m + ${PROJECT_ROOT}\functions\@eegobj\fieldnames.m + ${PROJECT_ROOT}\functions\@eegobj\horzcat2.m + ${PROJECT_ROOT}\functions\@eegobj\isfield.m + ${PROJECT_ROOT}\functions\@eegobj\isstruct.m + ${PROJECT_ROOT}\functions\@eegobj\length.m + ${PROJECT_ROOT}\functions\@eegobj\orderfields.m + ${PROJECT_ROOT}\functions\@eegobj\rmfield.m + ${PROJECT_ROOT}\functions\@eegobj\simpletest.m + ${PROJECT_ROOT}\functions\@eegobj\subsasgn.m + ${PROJECT_ROOT}\functions\@eegobj\subsref.m + ${PROJECT_ROOT}\functions\@mmo\binaryopp.m + ${PROJECT_ROOT}\functions\@mmo\bsxfun.m + ${PROJECT_ROOT}\functions\@mmo\changefile.m + ${PROJECT_ROOT}\functions\@mmo\checkcopies_local.m + ${PROJECT_ROOT}\functions\@mmo\checkworkspace.m + ${PROJECT_ROOT}\functions\@mmo\ctranspose.m + ${PROJECT_ROOT}\functions\@mmo\display.m + ${PROJECT_ROOT}\functions\@mmo\double.m + ${PROJECT_ROOT}\functions\@mmo\end.m + ${PROJECT_ROOT}\functions\@mmo\fft.m + ${PROJECT_ROOT}\functions\@mmo\isnumeric.m + ${PROJECT_ROOT}\functions\@mmo\length.m + ${PROJECT_ROOT}\functions\@mmo\mmo.m + ${PROJECT_ROOT}\functions\@mmo\ndims.m + ${PROJECT_ROOT}\functions\@mmo\permute.m + ${PROJECT_ROOT}\functions\@mmo\reshape.m + ${PROJECT_ROOT}\functions\@mmo\size.m + ${PROJECT_ROOT}\functions\@mmo\subsasgn.m + ${PROJECT_ROOT}\functions\@mmo\subsasgn_old.m + ${PROJECT_ROOT}\functions\@mmo\subsref.m + ${PROJECT_ROOT}\functions\@mmo\sum.m + ${PROJECT_ROOT}\functions\@mmo\transpose.m + ${PROJECT_ROOT}\functions\@mmo\unitaryopp.m + ${PROJECT_ROOT}\functions\@mmo\var.m + + + Z:\data\matlab\eeglab_versions\eeglabcompile\eeglab\for_testing\splash.png + Z:\data\matlab\eeglab_versions\eeglabcompile\eeglab\for_testing\EEGLAB.exe + Z:\data\matlab\eeglab_versions\eeglabcompile\eeglab\for_testing\readme.txt + + + + C:\Program Files\MATLAB\R2020a + + + + + + + + true + + + + + true + + + + + true + + + + + false + false + true + false + false + false + false + false + 10.0 + false + true + win64 + true + + + diff --git a/eeglablicense.txt b/eeglablicense.txt index 2718c875d..06027f641 100644 --- a/eeglablicense.txt +++ b/eeglablicense.txt @@ -1,236 +1,25 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - ADDITIONAL NOTE - -EEGLAB is designed and distributed for research purposes only. EEGLAB should -not be used for medical purposes. The authors accept no responsibility for its -use in this manner. +This is the license for the core for the eeglab.m function and +the source code in the "functions" folder. EEGLAB plugins (in the +"plugins" folder) may be released under different licenses. + +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. diff --git a/external/README.txt b/external/README.txt deleted file mode 100644 index 2a2aab5c9..000000000 --- a/external/README.txt +++ /dev/null @@ -1,7 +0,0 @@ -This folder use to contain modules external to EEGLAB -Now all external modules are treated as EEGLAB extensions -and this folder is not longer needed. - -This folder will be removed in subsequent EEGLAB releases. - -A. Delorme - Nov 30, 2013 diff --git a/functions/@eegobj/display.m b/functions/@eegobj/display.m index c997c67c4..4a2b5d1f2 100644 --- a/functions/@eegobj/display.m +++ b/functions/@eegobj/display.m @@ -1,16 +1,16 @@ -function display(this); - - disp(inputname(1)); - if length(this) == 1 - struct(this.EEG) - else - TMP = struct(this); - - TMP2 = TMP(1).EEG; - fieldorder = fieldnames(TMP2); - for index = 2:length(TMP) - TMP2(index) = orderfields(TMP(index).EEG, fieldorder); - end; - TMP2 - end; - +function display(this); + + disp(inputname(1)); + if length(this) == 1 + struct(this.EEG) + else + TMP = struct(this); + + TMP2 = TMP(1).EEG; + fieldorder = fieldnames(TMP2); + for index = 2:length(TMP) + TMP2(index) = orderfields(TMP(index).EEG, fieldorder); + end + TMP2 + end + diff --git a/functions/@eegobj/eegobj.m b/functions/@eegobj/eegobj.m index 7f3ad6139..3fb4ed1fa 100644 --- a/functions/@eegobj/eegobj.m +++ b/functions/@eegobj/eegobj.m @@ -1,14 +1,14 @@ -function this = eegobj(EEG); - - if nargin == 1 - if isa(EEG, 'eegobj') - this = EEG; - return; - end; - for index = 1:length(EEG) - TMP(index).EEG = EEG(index); - end; - else - TMP.EEG = eeg_emptyset; - end; - this = class(TMP, 'eegobj'); +function this = eegobj(EEG); + + if nargin == 1 + if isa(EEG, 'eegobj') + this = EEG; + return; + end + for index = 1:length(EEG) + TMP(index).EEG = EEG(index); + end + else + TMP.EEG = eeg_emptyset; + end + this = class(TMP, 'eegobj'); diff --git a/functions/@eegobj/horzcat2.m b/functions/@eegobj/horzcat2.m index 51b051b4a..944597712 100644 --- a/functions/@eegobj/horzcat2.m +++ b/functions/@eegobj/horzcat2.m @@ -2,4 +2,4 @@ this = varargin{1}; for index = 2:length(varargin) this.EEG(index) = varargin{index}.EEG; - end; + end diff --git a/functions/@eegobj/isfield.m b/functions/@eegobj/isfield.m index 1341b8e65..c854a3157 100644 --- a/functions/@eegobj/isfield.m +++ b/functions/@eegobj/isfield.m @@ -1,3 +1,3 @@ -function res = isfield(this, vals); - - res = isfield(struct(this(1).EEG), vals); +function res = isfield(this, vals); + + res = isfield(struct(this(1).EEG), vals); diff --git a/functions/@eegobj/isstruct.m b/functions/@eegobj/isstruct.m index 05cc0cf98..e686ab169 100644 --- a/functions/@eegobj/isstruct.m +++ b/functions/@eegobj/isstruct.m @@ -1,3 +1,3 @@ -function res = isstruct(this); - - res = 1; +function res = isstruct(this); + + res = 1; diff --git a/functions/@eegobj/length.m b/functions/@eegobj/length.m index 08943fee3..e31d74b34 100644 --- a/functions/@eegobj/length.m +++ b/functions/@eegobj/length.m @@ -1,14 +1,14 @@ -function res = length(this); - - tmp = struct(this); - %if any(cellfun(@length, { tmp.EEG }) > 1) - % error('EEG structure in object with more than 1 element') - %end; - try - res = length(tmp.EEG); - catch - res = length(tmp); - return; - end; - if res > 1, error('EEG structure in object with more than 1 element'); end; - res = length(tmp); +function res = length(this); + + tmp = struct(this); + %if any(cellfun(@length, { tmp.EEG }) > 1) + % error('EEG structure in object with more than 1 element') + %end + try + res = length(tmp.EEG); + catch + res = length(tmp); + return; + end + if res > 1, error('EEG structure in object with more than 1 element'); end + res = length(tmp); diff --git a/functions/@eegobj/orderfields.m b/functions/@eegobj/orderfields.m index ce9da6a9d..37046dfdf 100644 --- a/functions/@eegobj/orderfields.m +++ b/functions/@eegobj/orderfields.m @@ -1,5 +1,5 @@ -function this = orderfields(this, vals); - - for index = 1:length(this) - this(index).EEG = orderfields(this(index).EEG, vals); - end; +function this = orderfields(this, vals); + + for index = 1:length(this) + this(index).EEG = orderfields(this(index).EEG, vals); + end diff --git a/functions/@eegobj/rmfield.m b/functions/@eegobj/rmfield.m index 4ce7320f6..2f1f58dd5 100644 --- a/functions/@eegobj/rmfield.m +++ b/functions/@eegobj/rmfield.m @@ -1,4 +1,4 @@ -function this = rmfield(this, vals); - - this.EEG = rmfield(this.EEG, vals); - \ No newline at end of file +function this = rmfield(this, vals); + + this.EEG = rmfield(this.EEG, vals); + diff --git a/functions/@eegobj/subsasgn.m b/functions/@eegobj/subsasgn.m index 18ec5c95c..82db480fd 100644 --- a/functions/@eegobj/subsasgn.m +++ b/functions/@eegobj/subsasgn.m @@ -1,68 +1,68 @@ -function this = subsasgn(this,index,c) - - if isempty(this) - this = eegobj; - end; - - % mulitple dataset - if strcmpi(index(1).type, '()') && length(index) == 1 % dataset assignement - if isempty(c) % suppression - this(index.subs{1}) = []; - else - % create empty structures if necessary - % not optimized for speed but compatible Octave 3.4 and Matlab - allfieldsori = fieldnames( this ); - allSetIndices = [ [(length(this)+1):(min(index.subs{1})-1)] index.subs{1} ]; - this(max(index.subs{1})) = this(1); - for j = 1:length(allfieldsori) - for i = allSetIndices - this(i).EEG.(allfieldsori{j}) = []; - end; - end; - - % create empty structure, replaces the code above but - % only compatible under Matlab - %allfieldsori = fieldnames( this ); - %tmpfields = allfieldsori; - %tmpfields(:,2) = cell(size(tmpfields)); - %tmpfields = tmpfields'; - %tmp = struct(tmpfields{:}) - %this(index.subs{1}) = tmp; - - % dealing with input object and making it a compatible - % structure - if isa(c, 'eegobj') - c2 = struct(c); - c = c2(1).EEG; - fieldorder = fieldnames(c); - for cIndexe = 2:length(c2) - c(cIndexe) = orderfields(c2(cIndexe).EEG, fieldorder); - end; - end; - - allfields = fieldnames( c ); - for i=1:length( allfields ) - for j = 1:length(index.subs{1}) - this(index.subs{1}(j)).EEG.(allfields{i}) = c(min(j, length(c))).(allfields{i}); - end; - %this(index.subs(1)).EEG = setfield(this(index.subs(1)).EEG, getfield(c, allfields{i}), allfields{i}); - %eval( ['this(' int2str(index.subs{1}) ').' allfields{i} ' = c.' allfields{i} ';' ]); - end; - %if ~isfield(c, 'datfile') & isfield(this, 'datfile') - % this(index.subs{1}).datfile = ''; - %end; - end; - elseif strcmpi(index(1).type, '()') - if length(index(1).subs{1}) > 1 - error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); - elseif length(this) < index(1).subs{1} - this(index(1).subs{1}) = eegobj; - end; - this(index(1).subs{1}).EEG = builtin('subsasgn', this(index(1).subs{1}).EEG, index(2:end), c); - elseif strcmpi(index(1).type, '.') - if length(this) > 1 - error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); - else - this.EEG = builtin('subsasgn', this.EEG, index, c); - end; - end; +function this = subsasgn(this,index,c) + + if isempty(this) + this = eegobj; + end + + % multiple dataset + if strcmpi(index(1).type, '()') && length(index) == 1 % dataset assignment + if isempty(c) % suppression + this(index.subs{1}) = []; + else + % create empty structures if necessary + % not optimized for speed but compatible Octave 3.4 and Matlab + allfieldsori = fieldnames( this ); + allSetIndices = [ [(length(this)+1):(min(index.subs{1})-1)] index.subs{1} ]; + this(max(index.subs{1})) = this(1); + for j = 1:length(allfieldsori) + for i = allSetIndices + this(i).EEG.(allfieldsori{j}) = []; + end + end + + % create empty structure, replaces the code above but + % only compatible under Matlab + %allfieldsori = fieldnames( this ); + %tmpfields = allfieldsori; + %tmpfields(:,2) = cell(size(tmpfields)); + %tmpfields = tmpfields'; + %tmp = struct(tmpfields{:}) + %this(index.subs{1}) = tmp; + + % dealing with input object and making it a compatible + % structure + if isa(c, 'eegobj') + c2 = struct(c); + c = c2(1).EEG; + fieldorder = fieldnames(c); + for cIndexe = 2:length(c2) + c(cIndexe) = orderfields(c2(cIndexe).EEG, fieldorder); + end + end + + allfields = fieldnames( c ); + for i=1:length( allfields ) + for j = 1:length(index.subs{1}) + this(index.subs{1}(j)).EEG.(allfields{i}) = c(min(j, length(c))).(allfields{i}); + end + %this(index.subs(1)).EEG = setfield(this(index.subs(1)).EEG, getfield(c, allfields{i}), allfields{i}); + %eval( ['this(' int2str(index.subs{1}) ').' allfields{i} ' = c.' allfields{i} ';' ]); + end; + %if ~isfield(c, 'datfile') & isfield(this, 'datfile') + % this(index.subs{1}).datfile = ''; + %end + end + elseif strcmpi(index(1).type, '()') + if length(index(1).subs{1}) > 1 + error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + elseif length(this) < index(1).subs{1} + this(index(1).subs{1}) = eegobj; + end + this(index(1).subs{1}).EEG = builtin('subsasgn', this(index(1).subs{1}).EEG, index(2:end), c); + elseif strcmpi(index(1).type, '.') + if length(this) > 1 + error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + else + this.EEG = builtin('subsasgn', this.EEG, index, c); + end + end diff --git a/functions/@eegobj/subsref.m b/functions/@eegobj/subsref.m index d4ba37ccc..c9d777a08 100644 --- a/functions/@eegobj/subsref.m +++ b/functions/@eegobj/subsref.m @@ -1,45 +1,47 @@ -function varargout = subsref(this,s) - -if strcmpi(s(1).type, '()') && length(this) > 1 - %if length(s(1).subs{1}) - % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); - %end; - -% if length(s) == 1 -% b = this(s(1).subs{1}); -% else -% b = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end)); -% end; - - if length(s) == 1 - varargout{1} = this(s(1).subs{1}); - elseif length(s(1).subs{1}) > 1 - for index = 1:length(s(1).subs{1}) - varargout{1}{index} = builtin('subsref', this(s(1).subs{1}(index)).EEG, s(2:end)); - end; - else - varargout{1} = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end)); - end; -elseif strcmpi(s(1).type, '.') && length(this) > 1 - for index = 1:length(this) - varargout{index} = builtin('subsref', this(index).EEG, s); - end; - %if length(s) > 1 && iscell(s(2).subs) && length(s(2).subs{1}) - % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); - %end; -else - varargout{1} = builtin('subsref', this.EEG, s); -end; - - -% return; -% -% % SUBSREF -% switch s.type -% case '()' -% b = getfield(a.rawbit, s.subs); -% case '.' -% b = getfield(struct(a), s.subs); -% otherwise -% error('Wrong class argument') -% end +% support function for eegobj + +function varargout = subsref(this,s) + +if strcmpi(s(1).type, '()') && length(this) > 1 + %if length(s(1).subs{1}) + % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + %end + +% if length(s) == 1 +% b = this(s(1).subs{1}); +% else +% b = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end)); +% end + + if length(s) == 1 + varargout{1} = this(s(1).subs{1}); + elseif length(s(1).subs{1}) > 1 + for index = 1:length(s(1).subs{1}) + varargout{1}{index} = builtin('subsref', this(s(1).subs{1}(index)).EEG, s(2:end)); + end + else + varargout{1} = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end)); + end +elseif strcmpi(s(1).type, '.') && length(this) > 1 + for index = 1:length(this) + varargout{index} = builtin('subsref', this(index).EEG, s); + end + %if length(s) > 1 && iscell(s(2).subs) && length(s(2).subs{1}) + % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + %end +else + varargout{1} = builtin('subsref', this.EEG, s); +end + + +% return; +% +% % SUBSREF +% switch s.type +% case '()' +% b = getfield(a.rawbit, s.subs); +% case '.' +% b = getfield(struct(a), s.subs); +% otherwise +% error('Wrong class argument') +% end diff --git a/functions/@memmapdata/display.m b/functions/@memmapdata/display.m index fc815aef2..1d4d21faa 100644 --- a/functions/@memmapdata/display.m +++ b/functions/@memmapdata/display.m @@ -1,22 +1,33 @@ -% display() - display an EEG data class underlying structure +% DISPLAY - display an EEG data class underlying structure % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 b = display(a) @@ -33,4 +44,4 @@ a.data.data.x; else permute(a, [3 1 2]); - end; + end diff --git a/functions/@memmapdata/double.m b/functions/@memmapdata/double.m index 36031d573..1a9c0fce2 100644 --- a/functions/@memmapdata/double.m +++ b/functions/@memmapdata/double.m @@ -1,3 +1,3 @@ function res = double(a); -res = double(a.data.data.x); \ No newline at end of file +res = double(a.data.data.x); diff --git a/functions/@memmapdata/end.m b/functions/@memmapdata/end.m index 2e726d445..27a750126 100644 --- a/functions/@memmapdata/end.m +++ b/functions/@memmapdata/end.m @@ -1,22 +1,33 @@ -% end() - last index to memmapdata array +% END - last index to memmapdata array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 s = end(a, k, n); diff --git a/functions/@memmapdata/isnumeric.m b/functions/@memmapdata/isnumeric.m index ffd3d7447..fd1ab175f 100644 --- a/functions/@memmapdata/isnumeric.m +++ b/functions/@memmapdata/isnumeric.m @@ -1,22 +1,33 @@ -% isnumeric() - returns 1 +% ISNUMERIC - returns 1 % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 r = isnumeric(a) diff --git a/functions/@memmapdata/length.m b/functions/@memmapdata/length.m index e8a3250cf..e630df8b4 100644 --- a/functions/@memmapdata/length.m +++ b/functions/@memmapdata/length.m @@ -1,22 +1,33 @@ -% length() - length of memory mapped underlying array +% LENGTH - length of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 s = length(a) diff --git a/functions/@memmapdata/memmapdata.m b/functions/@memmapdata/memmapdata.m index f7b22efe0..069f4651a 100644 --- a/functions/@memmapdata/memmapdata.m +++ b/functions/@memmapdata/memmapdata.m @@ -1,4 +1,4 @@ -% memmapdata() - create a memory-mapped data class +% MEMMAPDATA - create a memory-mapped data class % % Usage: % >> data_class = memmapdata(data); @@ -13,29 +13,40 @@ % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 dataout = memmapdata(data, datadims); dataout.fileformat = 'normal'; - if isstr(data) + if ischar(data) if length(data) > 3 if strcmpi('.dat', data(end-3:end)) dataout.fileformat = 'transposed'; - end; - end; + end + end % check that the file is not empty % -------------------------------- @@ -44,15 +55,15 @@ error([ 'Data file ''' data '''not found' ]); elseif a(1).bytes == 0 error([ 'Empty data file ''' data '''' ]); - end; + end if ~strcmpi(dataout.fileformat, 'transposed') dataout.data = memmapfile(data, 'writable', false, 'format', { 'single' datadims 'x' }); else dataout.data = memmapfile(data, 'writable', false, 'format', { 'single' [ datadims(2:end) datadims(1) ] 'x' }); - end; + end dataout = class(dataout,'memmapdata'); else dataout = data; - end; + end diff --git a/functions/@memmapdata/msize.m b/functions/@memmapdata/msize.m deleted file mode 100644 index 8c4210fb4..000000000 --- a/functions/@memmapdata/msize.m +++ /dev/null @@ -1,3 +0,0 @@ -function s = msize(a); - - asdfdsa; diff --git a/functions/@memmapdata/ndims.m b/functions/@memmapdata/ndims.m index f77b01ca0..4f9c621d6 100644 --- a/functions/@memmapdata/ndims.m +++ b/functions/@memmapdata/ndims.m @@ -1,31 +1,42 @@ -% ndims() - number of dimension of memory mapped underlying array +% NDIMS - number of dimension of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 s = ndims(a) if ~strcmpi(a.fileformat, 'transposed') if a.data.Format{2}(3) == 1, s = 2; else s = 3; - end; + end else if a.data.Format{2}(2) == 1, s = 2; else s = 3; - end; - end; + end + end diff --git a/functions/@memmapdata/reshape.m b/functions/@memmapdata/reshape.m index e5c07b1d8..c46193b12 100644 --- a/functions/@memmapdata/reshape.m +++ b/functions/@memmapdata/reshape.m @@ -1,22 +1,33 @@ -% reshape() - reshape of memory mapped underlying array +% RESHAPE - reshape of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 a = reshape(a,d1,d2,d3) @@ -26,11 +37,11 @@ d1 = [ d1 d2 d3 ]; elseif nargin > 2 d1 = [ d1 d2 ]; - end; + end if prod(size(a)) ~= prod(d1) error('Wrong dimensions for reshaping'); - end; + end if ~strcmpi(a.fileformat, 'transposed') a.data.format{2} = d1; @@ -41,5 +52,5 @@ a.data.format{2} = [d1(2) d1(1)]; else a.data.format{2} = d1([2 3 1]); - end; - end; + end + end diff --git a/functions/@memmapdata/size.m b/functions/@memmapdata/size.m index 1a287837d..131c2bafd 100644 --- a/functions/@memmapdata/size.m +++ b/functions/@memmapdata/size.m @@ -1,22 +1,33 @@ -% size() - size of memory mapped underlying array +% SIZE - size of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [s s2 s3] = size(a,dim) @@ -28,19 +39,19 @@ if length(s) == 2, s = s([2 1]); elseif length(s) == 3 s = [s(3) s(1) s(2)]; - end; - end; - end; + end + end + end if nargin > 1 s = [s 1]; s = s(dim); - end; + end if nargout > 2 s3 = s(3); - end; + end if nargout > 1 s2 = s(2); s = s(1); - end; + end diff --git a/functions/@memmapdata/subsasgn.m b/functions/@memmapdata/subsasgn.m index 8c8e2a4de..68f11ead4 100644 --- a/functions/@memmapdata/subsasgn.m +++ b/functions/@memmapdata/subsasgn.m @@ -1,22 +1,33 @@ -% subsasgn() - define index assignment for eegdata objects +% SUBSASGN - define index assignment for eegdata objects % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 b = subsasgn(a,index,val) @@ -35,7 +46,7 @@ case 2, a.data(index.subs{1}, index.subs{2}) = val; case 3, a.data(index.subs{1}, index.subs{2}, index.subs{3}) = val; case 4, a.data(index.subs{1}, index.subs{2}, index.subs{3}, index.subs{4}) = val; - end; + end case '.' switch index.subs case 'srate' diff --git a/functions/@memmapdata/subsref.m b/functions/@memmapdata/subsref.m index 100f1437c..a90e0048e 100644 --- a/functions/@memmapdata/subsref.m +++ b/functions/@memmapdata/subsref.m @@ -1,28 +1,39 @@ -% subsref() - index eegdata class +% SUBSREF - index eegdata class % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 b = subsref(a,s) if s(1).type == '.' b = builtin('subsref', struct(a), s); return; - end; + end subs = s(1).subs; finaldim = cellfun('length', subs); @@ -30,56 +41,56 @@ % one dimension input % ------------------- if length(s(1).subs) == 1 - if isstr(subs{1}) + if ischar(subs{1}) subs{1} = [1:size(a,1)]; subs{2} = [1:size(a,2)]; - if ndims(a) == 3, subs{3} = [1:size(a,3)]; end; + if ndims(a) == 3, subs{3} = [1:size(a,3)]; end finaldim = prod(size(a)); - end; + end % two dimension input % ------------------- elseif length(s(1).subs) == 2 - if isstr(subs{1}), subs{1} = [1:size(a,1)]; end; + if ischar(subs{1}), subs{1} = [1:size(a,1)]; end - if isstr(subs{2}), + if ischar(subs{2}), subs{2} = [1:size(a,2)]; - if ndims(a) == 3, subs{3} = [1:size(a,3)]; end; - end; + if ndims(a) == 3, subs{3} = [1:size(a,3)]; end + end if length(subs) == 3 finaldim = [ length(subs{1}) length(subs{2})*length(subs{3}) ]; else finaldim = [ length(subs{1}) length(subs{2}) ]; - end; + end % three dimension input % --------------------- elseif length(s(1).subs) == 3 - if isstr(subs{1}), subs{1} = [1:size(a,1)]; end; - if isstr(subs{2}), subs{2} = [1:size(a,2)]; end; + if ischar(subs{1}), subs{1} = [1:size(a,1)]; end + if ischar(subs{2}), subs{2} = [1:size(a,2)]; end if ndims(a) == 2, subs(3) = []; else - if isstr(subs{3}), subs{3} = [1:size(a,3)]; end; - end; + if ischar(subs{3}), subs{3} = [1:size(a,3)]; end + end finaldim = cellfun('length', subs); - end; + end % non-transposed data % ------------------- if ~strcmpi(a.fileformat, 'transposed') - if length(subs) == 1, b = a.data.data.x(subs{1}); end; - if length(subs) == 2, b = a.data.data.x(subs{1}, subs{2}); end; - if length(subs) == 3, b = a.data.data.x(subs{1}, subs{2}, subs{3}); end; + if length(subs) == 1, b = a.data.data.x(subs{1}); end + if length(subs) == 2, b = a.data.data.x(subs{1}, subs{2}); end + if length(subs) == 3, b = a.data.data.x(subs{1}, subs{2}, subs{3}); end else if ndims(a) == 2 - %if length(s) == 0, b = transpose(a.data.data.x); return; end; - if length(s(1).subs) == 1, b = a.data.data.x(s(1).subs{1})'; end; - if length(s(1).subs) == 2, b = a.data.data.x(s(1).subs{2}, s(1).subs{1})'; end; - if length(s(1).subs) == 3, b = a.data.data.x(s(1).subs{2}, s(1).subs{1})'; end; + %if length(s) == 0, b = transpose(a.data.data.x); return; end + if length(s(1).subs) == 1, b = a.data.data.x(s(1).subs{1})'; end + if length(s(1).subs) == 2, b = a.data.data.x(s(1).subs{2}, s(1).subs{1})'; end + if length(s(1).subs) == 3, b = a.data.data.x(s(1).subs{2}, s(1).subs{1})'; end else - %if length(s) == 0, b = permute(a.data.data.x, [3 1 2]); return; end; + %if length(s) == 0, b = permute(a.data.data.x, [3 1 2]); return; end if length(subs) == 1, inds1 = mod(subs{1}-1, size(a,1))+1; inds2 = mod((subs{1}-inds1)/size(a,1), size(a,2))+1; @@ -87,7 +98,7 @@ inds = (inds1-1)*size(a,2)*size(a,3) + (inds3-1)*size(a,2) + inds2; b = a.data.data.x(inds); else - if length(subs) < 2, subs{3} = 1; end; + if length(subs) < 2, subs{3} = 1; end % repmat if several indices in different dimensions % ------------------------------------------------- @@ -99,11 +110,11 @@ inds = (subs{1}-1)*a.data.Format{2}(1)*a.data.Format{2}(2) + (subs{3}-1)*a.data.Format{2}(1) + subs{2}; inds = reshape(inds, [1 prod(size(inds))]); b = a.data.data.x(inds); - end; - end; - end; + end + end + end - if length(finaldim) == 1, finaldim(2) = 1; end; + if length(finaldim) == 1, finaldim(2) = 1; end b = reshape(b, finaldim); % 2 dims diff --git a/functions/@memmapdata/sum.m b/functions/@memmapdata/sum.m index d7a7af17e..936925e06 100644 --- a/functions/@memmapdata/sum.m +++ b/functions/@memmapdata/sum.m @@ -1,28 +1,39 @@ -% sum() - sum of memory mapped underlying array +% SUM - sum of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [s] = sum(a,dim) if nargin < 2 dim = 1; - end; + end %b = (:,:,:); if ~strcmpi(a.fileformat, 'transposed') @@ -37,10 +48,10 @@ if dim == 1 dim = 2; else dim = 1; - end; + end s = sum(a.data.data.x, dim)'; - end; - end; + end + end return; % do pnts by pnts if dim = 1 @@ -49,16 +60,16 @@ % s = zeros(size(a,2), size(a,3)); % for i=1:size(a,2) % s(i,:) = mean(a.data.data.x(:,i,:)); -% end; +% end % elseif dim == 1 % s = zeros(size(a,1), size(a,1)); % for i=1:size(a,1) % s(i,:) = mean(a.data.data.x(:,:,:)); -% end; +% end % % % s = builtin('sum', rand(10,10), dim); %if length(size(a)) > 2 %else s = sum(a(:,:,:), dim); - %end; + %end diff --git a/functions/@mmo/binaryopp.m b/functions/@mmo/binaryopp.m index c642f6140..e5dcf02e1 100644 --- a/functions/@mmo/binaryopp.m +++ b/functions/@mmo/binaryopp.m @@ -1,14 +1,14 @@ function obj3 = binaryopp(f, obj1, obj2) - if isa(obj2, 'mmo'), tmpobj = obj2; obj2 = obj1; obj1 = tmpobj; clear tmpobj; end; + if isa(obj2, 'mmo'), tmpobj = obj2; obj2 = obj1; obj1 = tmpobj; clear tmpobj; end if ~isequal(size(obj1), size(obj2)) && prod(size(obj2)) ~= 1 error('Matrix dimensions must agree.'); - end; + end data1 = memmapfile(obj1.dataFile, 'writable', obj1.writable, 'format', { 'single' obj1.dimensions 'x' }); if isa(obj2, 'mmo'), data2 = memmapfile(obj2.dataFile, 'writable', obj2.writable, 'format', { 'single' obj2.dimensions 'x' }); else data2 = obj2; - end; + end % make new memory mapped data file (blank) % -------------------------------- @@ -22,9 +22,9 @@ if prod(size(data2)) == 1 tmpdata = f(subsref(data1.Data.x, ss), data2); else tmpdata = f(subsref(data1.Data.x, ss), subsref(data2.Data.x, ss)); - end; + end fwrite(fid, tmpdata, 'float'); - end; + end fclose(fid); % create object diff --git a/functions/@mmo/bsxfun.m b/functions/@mmo/bsxfun.m index 4dc48ed4b..75ba91878 100644 --- a/functions/@mmo/bsxfun.m +++ b/functions/@mmo/bsxfun.m @@ -1,6 +1,6 @@ function obj3 = bsxfun(f, obj1, obj2) - if isa(obj2, 'mmo'), error('bsxfun does not work yet with the second argument being a memory mapped object'); end; + if isa(obj2, 'mmo'), error('bsxfun does not work yet with the second argument being a memory mapped object'); end data1 = memmapfile(obj1.dataFile, 'writable', obj1.writable, 'format', { 'single' obj1.dimensions 'x' }); data2 = obj2; @@ -14,12 +14,12 @@ ss.subs(1:length(s1)-1) = { ':' }; if length(s1) == length(s2) && s1(end) == s2(end) error('bsxfun does not work on the last dimension'); - end; + end for index = 1:s1(end) % scan last dimension ss.subs{length(s1)} = index; tmpdata = bsxfun(f,subsref(data1.Data.x, ss), data2); fwrite(fid, tmpdata, 'float'); - end; + end fclose(fid); % create object diff --git a/functions/@mmo/changefile.m b/functions/@mmo/changefile.m index d9fa2d6e2..f7971879b 100644 --- a/functions/@mmo/changefile.m +++ b/functions/@mmo/changefile.m @@ -4,4 +4,4 @@ movefile(obj.dataFile, newfile); obj.dataFile = newfile; - obj.writable = false; \ No newline at end of file + obj.writable = false; diff --git a/functions/@mmo/checkcopies_local.m b/functions/@mmo/checkcopies_local.m index 93e32ea87..249d15377 100644 --- a/functions/@mmo/checkcopies_local.m +++ b/functions/@mmo/checkcopies_local.m @@ -6,16 +6,16 @@ for ilen = 1:length(arg) for index = fieldnames(arg)' ncopies = ncopies + checkcopies_local(obj, arg(ilen).(index{1})); - if ncopies > 1, return; end; - end; - end; + if ncopies > 1, return; end + end + end elseif iscell(arg) for index = 1:length(arg(:)) ncopies = ncopies + checkcopies_local(obj, arg{index}); - if ncopies > 1, return; end; - end; + if ncopies > 1, return; end + end elseif isa(arg, 'mmo') && isequal(obj, arg) ncopies = 1; else ncopies = 0; -end; \ No newline at end of file +end diff --git a/functions/@mmo/checkworkspace.m b/functions/@mmo/checkworkspace.m index 8fb590d35..1e6cde6d4 100644 --- a/functions/@mmo/checkworkspace.m +++ b/functions/@mmo/checkworkspace.m @@ -22,14 +22,14 @@ subFlag = false; elseif ~isequal(obj.workspace(index+index2), stack(index2+1)) subFlag = false; - end; - end; - end; - if subFlag, return; end; - end; - end; + end + end + end + if subFlag, return; end + end + end - % if subfunction, must be a copie + % if subfunction, must be a copy if ~isempty(obj.workspace) && strcmpi(stack(end).file, obj.workspace(end).file) && ... ~strcmpi(stack(end).name, obj.workspace(end).name) % We are within a subfunction. The MMO must have @@ -51,11 +51,11 @@ % we are in a script. while ~isempty(stack) && ~isequal(stack, obj.workspace) stack(1) = []; - end; + end if ~isequal(stack, obj.workspace) ncopies = 2; - end; - end; - end; - end; -end; + end + end + end + end +end diff --git a/functions/@mmo/ctranspose.m b/functions/@mmo/ctranspose.m index ebba20612..3878559ba 100644 --- a/functions/@mmo/ctranspose.m +++ b/functions/@mmo/ctranspose.m @@ -1,11 +1,11 @@ function res = ctranspose(obj,useconj); if nargin == 1 useconj = 1; - end; + end if length(obj.dimensions) > 2 error('Cannot transpose array'); - end; + end % make new memory mapped data file % -------------------------------- @@ -26,15 +26,15 @@ s.subs = { ':' index }; if useconj, tmpMMO2.Data.x(index,:) = conj(subsref(tmpMMO1.Data.x,s)); else tmpMMO2.Data.x(:,index) = subsref(tmpMMO1.Data.x,s); - end; - end; + end + end else for index = 1:size(obj,1) s.type = '()'; s.subs = { index ':' }; if useconj, tmpMMO2.Data.x(:,index) = conj(subsref(tmpMMO1.Data.x,s)); else tmpMMO2.Data.x(:,index) = subsref(tmpMMO1.Data.x,s); - end; - end; - end; - \ No newline at end of file + end + end + end + diff --git a/functions/@mmo/display.m b/functions/@mmo/display.m index 5355c3d57..f56d854b7 100644 --- a/functions/@mmo/display.m +++ b/functions/@mmo/display.m @@ -1,26 +1,37 @@ -% display() - display an EEG data class underlying structure +% DISPLAY - display an EEG data class underlying structure % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 display(obj); tmpMMO = memmapfile(obj.dataFile, 'writable', obj.writable, 'format', { 'single' obj.dimensions 'x' }); - if obj.transposed, disp('Warning: data does not display properly for memory mapped file which have been transposed'); end; + if obj.transposed, disp('Warning: data does not display properly for memory mapped file which have been transposed'); end disp(tmpMMO.data.x); - \ No newline at end of file + diff --git a/functions/@mmo/double.m b/functions/@mmo/double.m index e5748b97d..d92222154 100644 --- a/functions/@mmo/double.m +++ b/functions/@mmo/double.m @@ -1,3 +1,3 @@ function a = double(a); -return; \ No newline at end of file +return; diff --git a/functions/@mmo/end.m b/functions/@mmo/end.m index 2e726d445..27a750126 100644 --- a/functions/@mmo/end.m +++ b/functions/@mmo/end.m @@ -1,22 +1,33 @@ -% end() - last index to memmapdata array +% END - last index to memmapdata array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 s = end(a, k, n); diff --git a/functions/@mmo/isnumeric.m b/functions/@mmo/isnumeric.m index ffd3d7447..fd1ab175f 100644 --- a/functions/@mmo/isnumeric.m +++ b/functions/@mmo/isnumeric.m @@ -1,22 +1,33 @@ -% isnumeric() - returns 1 +% ISNUMERIC - returns 1 % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 r = isnumeric(a) diff --git a/functions/@mmo/length.m b/functions/@mmo/length.m index e8a3250cf..e630df8b4 100644 --- a/functions/@mmo/length.m +++ b/functions/@mmo/length.m @@ -1,22 +1,33 @@ -% length() - length of memory mapped underlying array +% LENGTH - length of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 s = length(a) diff --git a/functions/@mmo/mmo.m b/functions/@mmo/mmo.m index d5470e4ba..4f365267e 100644 --- a/functions/@mmo/mmo.m +++ b/functions/@mmo/mmo.m @@ -1,4 +1,4 @@ -% mmo() - create a memory-mapped data class +% MMO - create a memory-mapped data class % % Usage: % >> data_class = mmo(data); @@ -13,19 +13,30 @@ % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. classdef mmo properties @@ -42,38 +53,38 @@ function dataout = mmo(dataFileIn, datadims, writableVal, transposedVal, debugVal) if nargin < 3 writableVal = true; - end; + end if nargin < 4 transposedVal = false; - end; + end if nargin < 5 debugVal = false; - end; + end % check that the file is not empty % -------------------------------- if ~isempty(dataFileIn) - if ~isstr(dataFileIn) + if ~ischar(dataFileIn) error('First input must be a file name'); - end; + end dirContent = dir(dataFileIn); if isempty(dirContent) error([ 'Data file ''' dataFileIn '''not found' ]); elseif dirContent(1).bytes == 0 error([ 'Empty data file ''' dataFileIn '''' ]); - end; + end else dataFileIn = mmo.getnewfilename; fid = fopen(dataFileIn, 'w'); - if fid == -1, error('Cannot open new file'); end; - if length(datadims) == 1, datadims(2) = 1; end; + if fid == -1, error('Cannot open new file'); end + if length(datadims) == 1, datadims(2) = 1; end tmpdata = zeros(1, prod(datadims(2:end)), 'single'); for index = 1:datadims(1) fwrite(fid, tmpdata, 'float'); - end; + end fclose(fid); - end; + end % test memory map but discards it % ------------------------------- @@ -84,12 +95,12 @@ % ---------- while datadims(end) == 1 && length(datadims) > 1 datadims(end) = []; - end; + end if transposedVal if length(datadims) == 1, datadims = [1 datadims]; else datadims = [datadims(2:end) datadims(1)]; - end; - end; + end + end dataout.dataFile = dataFileIn; dataout.dimensions = datadims; @@ -129,13 +140,13 @@ elseif strcmpi(s(index).class, 'mmo') if s(index).persistent || s(index).global disp('Warning: mmo objects should not be made persistent or global. Behavior is unpredictable.'); - end; + end tmpVar = evalin('caller', s(index).name); - if isequal(tmpVar, obj), ncopies = ncopies + 1; end; - if ncopies > 1, break; end; - end; - end; - end; + if isequal(tmpVar, obj), ncopies = ncopies + 1; end + if ncopies > 1, break; end + end + end + end end % numerical implementations of basic functions @@ -149,6 +160,6 @@ end methods (Static) - function str = getnewfilename; str = fullfile(gettempfolder(true), sprintf('memapdata_%.9d%.9d.fdt', round(rand(1)*10^9), round(rand(1)*10^9))); end; + function str = getnewfilename; str = fullfile(gettempfolder(true), sprintf('memapdata_%.9d%.9d.fdt', round(rand(1)*10^9), round(rand(1)*10^9))); end end end diff --git a/functions/@mmo/ndims.m b/functions/@mmo/ndims.m index 055b0da04..370892264 100644 --- a/functions/@mmo/ndims.m +++ b/functions/@mmo/ndims.m @@ -1,25 +1,36 @@ -% ndims() - number of dimension of memory mapped underlying array +% NDIMS - number of dimension of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 res = ndims(obj) if length(obj.dimensions) <= 2 || all(obj.dimensions(3:end) == 1), res = 2; else res = length(obj.dimensions); - end; + end diff --git a/functions/@mmo/permute.m b/functions/@mmo/permute.m index ea17d2732..da3551e4e 100644 --- a/functions/@mmo/permute.m +++ b/functions/@mmo/permute.m @@ -4,7 +4,7 @@ error('Max 3 dimensions for permutation'); elseif length(dims) == 2 error('Permutation with 2 dimensions: use transpose instead'); -end; +end newFileName = mmo.getnewfilename; copyfile(obj.dataFile, newFileName); @@ -23,15 +23,15 @@ s.subs = { i1 ':' ':' }; tmpdata = squeeze(subsref(tmpMMO1.Data.x,s)); - if all(dims == [2 1 3]), tmpMMO2.Data.x( :,i1, :) = reshape(tmpdata , d(1), 1, d(3)); end; - if all(dims == [3 1 2]), tmpMMO2.Data.x( :,i1, :) = reshape(tmpdata', d(1), 1, d(3)); end; + if all(dims == [2 1 3]), tmpMMO2.Data.x( :,i1, :) = reshape(tmpdata , d(1), 1, d(3)); end + if all(dims == [3 1 2]), tmpMMO2.Data.x( :,i1, :) = reshape(tmpdata', d(1), 1, d(3)); end - if all(dims == [2 3 1]), tmpMMO2.Data.x( :, :,i1) = reshape(tmpdata , d(1), d(2), 1); end; - if all(dims == [3 2 1]), tmpMMO2.Data.x( :, :,i1) = reshape(tmpdata', d(1), d(2), 1); end; + if all(dims == [2 3 1]), tmpMMO2.Data.x( :, :,i1) = reshape(tmpdata , d(1), d(2), 1); end + if all(dims == [3 2 1]), tmpMMO2.Data.x( :, :,i1) = reshape(tmpdata', d(1), d(2), 1); end - if all(dims == [1 2 3]), tmpMMO2.Data.x(i1, :, :) = reshape(tmpdata , 1, d(2), d(3)); end; - if all(dims == [1 3 2]), tmpMMO2.Data.x(i1, :, :) = reshape(tmpdata', 1, d(2), d(3)); end; -end; + if all(dims == [1 2 3]), tmpMMO2.Data.x(i1, :, :) = reshape(tmpdata , 1, d(2), d(3)); end + if all(dims == [1 3 2]), tmpMMO2.Data.x(i1, :, :) = reshape(tmpdata', 1, d(2), d(3)); end +end % slower versions below % for i1 = 1:obj.dimensions(1) @@ -39,27 +39,27 @@ % s.type = '()'; % s.subs = { i1 ':' i2 }; % tmpdata = subsref(tmpMMO1.Data.x,s); -% if all(dims == [2 1 3]), tmpMMO2.Data.x( :,i1,i2) = tmpdata; end; -% if all(dims == [2 3 1]), tmpMMO2.Data.x( :,i2,i1) = tmpdata; end; +% if all(dims == [2 1 3]), tmpMMO2.Data.x( :,i1,i2) = tmpdata; end +% if all(dims == [2 3 1]), tmpMMO2.Data.x( :,i2,i1) = tmpdata; end % -% if all(dims == [1 2 3]), tmpMMO2.Data.x(i1, :,i2) = tmpdata; end; -% if all(dims == [3 2 1]), tmpMMO2.Data.x(i2, :,i1) = tmpdata; end; +% if all(dims == [1 2 3]), tmpMMO2.Data.x(i1, :,i2) = tmpdata; end +% if all(dims == [3 2 1]), tmpMMO2.Data.x(i2, :,i1) = tmpdata; end % -% if all(dims == [1 3 2]), tmpMMO2.Data.x(i1,i2, :) = tmpdata; end; -% if all(dims == [3 1 2]), tmpMMO2.Data.x(i2,i1, :) = tmpdata; end; -% end; -% end; +% if all(dims == [1 3 2]), tmpMMO2.Data.x(i1,i2, :) = tmpdata; end +% if all(dims == [3 1 2]), tmpMMO2.Data.x(i2,i1, :) = tmpdata; end +% end +% end % % for i1 = 1:obj.dimensions(2) % for i2 = 1:obj.dimensions(3) % s.type = '()'; % s.subs = { ':' i1 i2 }; % tmpdata = subsref(tmpMMO1.Data.x,s); -% if all(dims == [1 2 3]), tmpMMO2.Data.x( :,i1,i2) = tmpdata; end; -% if all(dims == [1 3 2]), tmpMMO2.Data.x( :,i2,i1) = tmpdata; end; -% if all(dims == [2 1 3]), tmpMMO2.Data.x(i1, :,i2) = tmpdata; end; -% if all(dims == [2 3 1]), tmpMMO2.Data.x(i1,i2, :) = tmpdata; end; -% if all(dims == [3 2 1]), tmpMMO2.Data.x(i2,i1, :) = tmpdata; end; -% if all(dims == [3 1 2]), tmpMMO2.Data.x(i2, :,i1) = tmpdata; end; -% end; -% end; +% if all(dims == [1 2 3]), tmpMMO2.Data.x( :,i1,i2) = tmpdata; end +% if all(dims == [1 3 2]), tmpMMO2.Data.x( :,i2,i1) = tmpdata; end +% if all(dims == [2 1 3]), tmpMMO2.Data.x(i1, :,i2) = tmpdata; end +% if all(dims == [2 3 1]), tmpMMO2.Data.x(i1,i2, :) = tmpdata; end +% if all(dims == [3 2 1]), tmpMMO2.Data.x(i2,i1, :) = tmpdata; end +% if all(dims == [3 1 2]), tmpMMO2.Data.x(i2, :,i1) = tmpdata; end +% end +% end diff --git a/functions/@mmo/reshape.m b/functions/@mmo/reshape.m index f38a3dd31..63dc09d1e 100644 --- a/functions/@mmo/reshape.m +++ b/functions/@mmo/reshape.m @@ -1,22 +1,33 @@ -% reshape() - reshape of memory mapped underlying array +% RESHAPE - reshape of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 obj = reshape(obj,d1,d2,d3) @@ -26,14 +37,14 @@ d1 = [ d1 d2 d3 ]; elseif nargin > 2 d1 = [ d1 d2 ]; - end; + end if prod(size(obj)) ~= prod(d1) error('Wrong dimensions for reshaping'); - end; + end if obj.transposed d1 = [d1(2:end) d1(1)]; - end; + end obj.dimensions = d1; diff --git a/functions/@mmo/size.m b/functions/@mmo/size.m index 5d9cb6b6c..738771323 100644 --- a/functions/@mmo/size.m +++ b/functions/@mmo/size.m @@ -1,35 +1,46 @@ -% size() - size of memory mapped underlying array +% SIZE - size of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [s varargout] = size(obj,dim) if obj.transposed if length(obj.dimensions) ~= 2 && length(obj.dimensions) ~= 3 error('Transposed array must be 2 or 3 dims'); - end; + end if length(obj.dimensions) == 2 tmpdimensions = [obj.dimensions(2) obj.dimensions(1)]; else tmpdimensions = [obj.dimensions(3) obj.dimensions(1:end-1)]; - end; + end else tmpdimensions = obj.dimensions; - end; + end s = tmpdimensions; @@ -38,7 +49,7 @@ s = 1; else s = s(dim); - end; + end else if nargout > 1 s = [s 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]; @@ -46,8 +57,8 @@ s = s(1); for index = 1:max(nargout,1)-1 varargout{index} = alls(index+1); - end; - end; - end; + end + end + end + - \ No newline at end of file diff --git a/functions/@mmo/subsasgn.m b/functions/@mmo/subsasgn.m index e8c09c2e1..7048590dd 100644 --- a/functions/@mmo/subsasgn.m +++ b/functions/@mmo/subsasgn.m @@ -1,30 +1,41 @@ -% subsasgn() - define index assignment for eegdata objects +% SUBSASGN - define index assignment for eegdata objects % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 obj = subsasgn(obj,ss,val) -% check empty assignement +% check empty assignment % ----------------------- for index = 1:length(ss(1).subs) - if isempty(ss(1).subs{index}), return; end; -end; + if isempty(ss(1).subs{index}), return; end +end % remove useless ":" % ------------------ @@ -33,31 +44,17 @@ ss(1).subs(end) = []; else break; - end; -end; + end +end % deal with transposed data % ------------------------- -if obj.transposed, ss = transposeindices(obj, ss); end; +if obj.transposed, ss = transposeindices(obj, ss); end % check stack and local variables % --------------------- ncopies = checkworkspace(obj); if ncopies < 2 - if isempty(inputname(1)) - vers = version; - indp = find(vers == '.'); - if str2num(vers(indp(1)+1)) > 1, vers = [ vers(1:indp(1)) '0' vers(indp(1)+1:end) ]; end; - indp = find(vers == '.'); - vers = str2num(vers(1:indp(2)-1)); - if vers >= 7.13 - % the problem with Matlab 2012a/2011b is that if the object called is - % in a field of a structure (empty inputname), the evaluation - % in the caller of the object variable is empty in 2012a. A bug - % repport has been submitted to Matlab - Arno - ncopies = ncopies + 1; - end; - end; s = evalin('caller', 'whos'); for index = 1:length(s) if strcmpi(s(index).class, 'struct') || strcmpi(s(index).class, 'cell') @@ -66,13 +63,13 @@ elseif strcmpi(s(index).class, 'mmo') if s(index).persistent || s(index).global disp('Warning: mmo objects should not be made persistent or global. Behavior is unpredictable.'); - end; + end tmpVar = evalin('caller', s(index).name); - if isequal(tmpVar, obj), ncopies = ncopies + 1; end; - if ncopies > 1, break; end; - end; - end; -end; + if isequal(tmpVar, obj), ncopies = ncopies + 1; end + if ncopies > 1, break; end + end + end +end % removing some entries % --------------------- @@ -90,13 +87,14 @@ nonSingleton = []; ss2 = ss; for index = 1:length(ss(1).subs) - if ~isstr(ss(1).subs{index}) % can only be ":" + if ~ischar(ss(1).subs{index}) % can only be ":" nonSingleton(end+1) = index; + if islogical( ss(1).subs{index}), ss(1).subs{index} = find( ss(1).subs{index}); end ss2(1).subs{index} = setdiff_bc([1:newdim1(index)], ss(1).subs{index}); % invert selection - end; - end; - if length(nonSingleton) > 1, error('A null assignment can have only one non-colon index'); end; - if isempty(nonSingleton), obj = []; return; end; + end + end + if length(nonSingleton) > 1, error('A null assignment can have only one non-colon index'); end + if isempty(nonSingleton), obj = []; return; end % compute new final dimension and copy data % ----------------------------------------- @@ -104,24 +102,25 @@ fid = fopen(newFileName, 'w'); newdim2 = [ prod(newdim2)-length(ss(1).subs{1}) ]; if ~(newdim1(1) > 1 && all(newdim1(2:end) == 1)), newdim2 = [1 newdim2]; - else newdim2 = [newdim2 1]; end; + else newdim2 = [newdim2 1]; end newindices = setdiff_bc([1:prod(newdim1)], ss(1).subs{1}); for index = newindices fwrite(fid, tmpMMO.Data.x(index), 'float'); - end; + end fclose(fid); + fprintf('Warning: memory mapped object writing might not be up to date in cache on network drive'); else if length(ss(1).subs) < length(newdim2) newdim2(length(ss(1).subs)) = prod(newdim2(length(ss(1).subs):end)); newdim2(length(ss(1).subs)+1:end) = []; if nonSingleton == length(ss(1).subs) ss2(1).subs{end} = setdiff_bc([1:newdim2(end)], ss(1).subs{end}); - end; - end; + end + end newdim2(nonSingleton) = newdim2(nonSingleton)-length(ss(1).subs{nonSingleton}); - if isstr(ss2.subs{end}) + if ischar(ss2.subs{end}) ss2.subs{end} = [1:prod(newdim1(length(ss2.subs):end))]; - end; + end ss3 = ss2; fid = fopen(newFileName, 'w'); @@ -132,16 +131,17 @@ ss3.subs{end} = ss2.subs{end}(index:min(index+inc, length(ss2.subs{end}))); tmpdata = subsref(tmpMMO.Data.x, ss3); fwrite(fid, tmpdata, 'float'); - end; + end fclose(fid); - end; + fprintf('Warning: memory mapped object writing might not be up to date in cache on network drive'); + end % delete file if necessary if ncopies == 1 && obj.writable delete(obj.dataFile); - end; + end - if obj.debug, disp('new copy created, old deleted (length 1)'); end; + if obj.debug, disp('new copy created, old deleted (length 1)'); end obj.dimensions = newdim2; obj.dataFile = newFileName; obj.writable = true; @@ -155,35 +155,35 @@ newdim1 = obj.dimensions; newdim2 = newdim1; if length(ss(1).subs) == 1 - if ~isstr(ss(1).subs{1}) && max(ss(1).subs{1}) > prod(newdim1) + if ~ischar(ss(1).subs{1}) && max(ss(1).subs{1}) > prod(newdim1) if length(newdim1) > 2 error('Attempt to grow array along ambiguous dimension.'); - end; - end; + end + end if max(ss(1).subs{1}) > prod(newdim2) notOneDim = find(newdim2 > 1); if length(notOneDim) == 1 newdim2(notOneDim) = max(ss(1).subs{1}); - end; - end; + end + end else - if length(newdim1) == 3 && newdim1(3) == 1, newdim1(end) = []; end; + if length(newdim1) == 3 && newdim1(3) == 1, newdim1(end) = []; end if length(ss(1).subs) == 2 && length(newdim1) == 3 - if ~isstr(ss(1).subs{2}) && max(ss(1).subs{2}) > prod(newdim1(2:end)) + if ~ischar(ss(1).subs{2}) && max(ss(1).subs{2}) > prod(newdim1(2:end)) error('Attempt to grow array along ambiguous dimension.'); - end; - if isnumeric(ss(1).subs{1}), newdim2(1) = max(max(ss(1).subs{1}), newdim2(1)); end; + end + if isnumeric(ss(1).subs{1}), newdim2(1) = max(max(ss(1).subs{1}), newdim2(1)); end else for index = 1:length(ss(1).subs) if isnumeric(ss(1).subs{index}) if index > length(newdim2) newdim2(index) = max(ss(1).subs{index}); else newdim2(index) = max(max(ss(1).subs{index}), newdim2(index)); - end; - end; - end; - end; - end; + end + end + end + end + end % create new array of new size if necessary % ----------------------------------------- @@ -212,22 +212,23 @@ else for index1 = 1:dim1(1) fwrite(fid, tmpMMO.Data.x(index1,index2,index3), 'float'); - end; - end; + end + end fwrite(fid, tmpdata1, 'float'); - end; - end; + end + end fwrite(fid, tmpdata2, 'float'); - end; + end fwrite(fid, tmpdata3, 'float'); fclose(fid); + fprintf('Warning: memory mapped object writing might not be up to date in cache on network drive'); % delete file if necessary if ncopies == 1 && obj.writable delete(obj.dataFile); - end; + end - if obj.debug, disp('new copy created, old deleted'); end; + if obj.debug, disp('new copy created, old deleted'); end obj.dimensions = newdim2; obj.dataFile = newFileName; obj.writable = true; @@ -240,10 +241,10 @@ copyfile(obj.dataFile, newFileName); obj.dataFile = newFileName; obj.writable = true; - if obj.debug, disp('new copy created'); end; + if obj.debug, disp('new copy created'); end else - if obj.debug, disp('using same copy'); end; - end; + if obj.debug, disp('using same copy'); end + end % copy new data tmpMMO = memmapfile(obj.dataFile, 'writable', obj.writable, 'format', { 'single' obj.dimensions 'x' }); @@ -263,15 +264,15 @@ % array, copy each channel for index1 = 1:size(val,1) ss2(1).subs{1} = index1; - if isstr(ss(1).subs{1}) ss3(1).subs{1} = index1; + if ischar(ss(1).subs{1}) ss3(1).subs{1} = index1; else ss3(1).subs{1} = ss(1).subs{1}(index1); - end; + end tmpMMO.Data.x = builtin('subsasgn', tmpMMO.Data.x, ss3, subsref(val,ss2)); - end; - end; - end; + end + end + end obj = updateWorkspace(obj); -end; +end diff --git a/functions/@mmo/subsasgn_old.m b/functions/@mmo/subsasgn_old.m index 018b4f517..9cb8e699f 100644 --- a/functions/@mmo/subsasgn_old.m +++ b/functions/@mmo/subsasgn_old.m @@ -1,22 +1,33 @@ -% subsasgn() - define index assignment for eegdata objects +% SUBSASGN - define index assignment for eegdata objects % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 obj = subsasgn(obj,ss,val) @@ -29,7 +40,7 @@ if ~isempty(stack) % check if we are in a different workspace if ~isequal(stack, obj.workspace) - % if subfunction, must be a copie + % if subfunction, must be a copy if ~isempty(obj.workspace) && strcmpi(stack(end).file, obj.workspace(end).file) && ... ~strcmpi(stack(end).name, obj.workspace(end).name) % We are within a subfunction. The MMO must have @@ -52,14 +63,14 @@ % we are in a script. while ~isempty(stack) && ~isequal(stack, obj.workspace) stack(1) = []; - end; + end if ~isequal(stack, obj.workspace) ncopies = 2; - end; - end; - end; - end; -end; + end + end + end + end +end % check local variables % --------------------- @@ -72,13 +83,13 @@ elseif strcmpi(s(index).class, 'mmo') if s(index).persistent || s(index).global disp('Warning: mmo objects should not be made persistent or global. Behavior is unpredictable.'); - end; + end tmpVar = evalin('caller', s(index).name); - if isequal(tmpVar, obj), ncopies = ncopies + 1; end; - if ncopies > 1, break; end; - end; - end; -end; + if isequal(tmpVar, obj), ncopies = ncopies + 1; end + if ncopies > 1, break; end + end + end +end % removing some entries % --------------------- @@ -95,13 +106,13 @@ % ---------------------------- nonSingleton = []; for index = 1:length(subs) - if ~isstr(subs{index}) % can only be ":" + if ~ischar(subs{index}) % can only be ":" nonSingleton(end+1) = index; subs2 = setdiff_bc([1:newdim1(index)], subs{index}); % invert selection - end; - end; - if length(nonSingleton) > 1, error('A null assignment can have only one non-colon index'); end; - if isempty(nonSingleton), obj = []; return; end; + end + end + if length(nonSingleton) > 1, error('A null assignment can have only one non-colon index'); end + if isempty(nonSingleton), obj = []; return; end % compute new final dimension % --------------------------- @@ -111,7 +122,7 @@ newindices = setdiff_bc([1:prod(newdim1)], ss(1).subs{1}); for index = newindices fwrite(fid, tmpMMO.Data.x(index), 'float'); - end; + end fclose(fid); else newdim2(nonSingleton) = newdim2(nonSingleton)-length(subs{index}); @@ -119,14 +130,14 @@ fid = fopen(newFileName, 'w'); fwrite(fid, tmpMMO.Data.x(index), 'float'); fclose(fid); - end; + end % delete file if necessary if ncopies == 1 && obj.writable delete(obj.dataFile); - end; + end - if obj.debug, disp('new copy created, old deleted (length 1)'); end; + if obj.debug, disp('new copy created, old deleted (length 1)'); end obj.dimensions = [1 newdim2]; obj.dataFile = newFileName; obj.writable = true; @@ -139,8 +150,8 @@ if index > length(newdim2) newdim2(index) = max(ss(1).subs{index}); else newdim2(index) = max(max(ss(1).subs{index}), newdim2(index)); - end; - end; + end + end % create new array of new size % ----------------------------------------- @@ -154,21 +165,21 @@ for index = 1:prod(newdim1(2:end)) fwrite(fid, tmpMMO.Data.x(:,index), 'float'); fwrite(fid, tmpdata, 'float'); - end; + end if prod(newadim1(2:end)) ~= prod(newdim2(2:end)) tmpdata = zeros(newdim2(1), 1, 'single'); for index = prod(newdim1(2:end))+1:prod(newdim2(2:end)) fwrite(fid, tmpdata, 'float'); - end; - end; + end + end fclose(fid); % delete file if necessary if ncopies == 1 && obj.writable delete(obj.dataFile); - end; + end - if obj.debug, disp('new copy created, old deleted'); end; + if obj.debug, disp('new copy created, old deleted'); end obj.dimensions = newdim2; obj.dataFile = newFileName; obj.writable = true; @@ -184,16 +195,16 @@ notOneDim = find(newdim2 > 1); if length(notOneDim) == 1 newdim2(notOneDim) = max(ss(1).subs{1}); - end; - end; + end + end else for index = 1:length(ss(1).subs) if index > length(newdim2) newdim2(index) = max(ss(1).subs{index}); else newdim2(index) = max(max(ss(1).subs{index}), newdim2(index)); - end; - end; - end; + end + end + end % create new array of new size if necessary % ----------------------------------------- @@ -208,21 +219,21 @@ for index = 1:prod(newdim1(2:end)) fwrite(fid, tmpMMO.Data.x(:,index), 'float'); fwrite(fid, tmpdata, 'float'); - end; + end if prod(newdim1(2:end)) ~= prod(newdim2(2:end)) tmpdata = zeros(newdim2(1), 1, 'single'); for index = prod(newdim1(2:end))+1:prod(newdim2(2:end)) fwrite(fid, tmpdata, 'float'); - end; - end; + end + end fclose(fid); % delete file if necessary if ncopies == 1 && obj.writable delete(obj.dataFile); - end; + end - if obj.debug, disp('new copy created, old deleted'); end; + if obj.debug, disp('new copy created, old deleted'); end obj.dimensions = newdim2; obj.dataFile = newFileName; obj.writable = true; @@ -235,15 +246,15 @@ copyfile(obj.dataFile, newFileName); obj.dataFile = newFileName; obj.writable = true; - if obj.debug, disp('new copy created'); end; + if obj.debug, disp('new copy created'); end else - if obj.debug, disp('using same copy'); end; - end; + if obj.debug, disp('using same copy'); end + end tmpMMO = memmapfile(obj.dataFile, 'writable', obj.writable, 'format', { 'single' obj.dimensions 'x' }); tmpMMO.Data.x = builtin('subsasgn', tmpMMO.Data.x, ss, val); -end; +end return; @@ -260,16 +271,16 @@ for ilen = 1:length(arg) for index = fieldnames(arg)' ncopies = ncopies + checkcopies_local(obj, arg(ilen).(index{1})); - if ncopies > 1, return; end; - end; - end; + if ncopies > 1, return; end + end + end elseif iscell(arg) for index = 1:length(arg(:)) ncopies = ncopies + checkcopies_local(obj, arg{index}); - if ncopies > 1, return; end; - end; + if ncopies > 1, return; end + end elseif isa(arg, 'mmo') && isequal(obj, arg) ncopies = 1; else ncopies = 0; -end; +end diff --git a/functions/@mmo/subsref.m b/functions/@mmo/subsref.m index 54d79141d..f1ba098e6 100644 --- a/functions/@mmo/subsref.m +++ b/functions/@mmo/subsref.m @@ -1,29 +1,40 @@ -% subsref() - index eegdata class +% SUBSREF - index eegdata class % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 res = subsref(obj,s) if strcmpi(s(1).type, '.') res = builtin('subsref', obj, s); return; - end; + end tmpMMO = memmapfile(obj.dataFile, 'writable', obj.writable, 'format', { 'single' obj.dimensions 'x' }); @@ -34,33 +45,33 @@ % ------------------- if length(s) > 1 || ~strcmpi(s(1).type, '()') error('MMO can only map single array data files'); - end; + end % deal with transposed data % ------------------------- - if obj.transposed, s = transposeindices(obj, s); end; + if obj.transposed, s = transposeindices(obj, s); end % convert : to real sizes % ----------------------- lastdim = length(subs); - if isstr(subs{end}) && ndims(obj) > lastdim + if ischar(subs{end}) && ndims(obj) > lastdim for index = lastdim+1:ndims(obj) if index > length(obj.dimensions) subs{index} = 1; else subs{index} = [1:obj.dimensions(index)]; - end; - end; - end; + end + end + end for index = 1:length(subs) - if isstr(subs{index}) % can only be ":" + if ischar(subs{index}) % can only be ":" if index > length(obj.dimensions) subs{index} = 1; else subs{index} = [1:obj.dimensions(index)]; - end; - end; - end; + end + end + end finaldim = cellfun(@length, subs); finaldim(lastdim) = prod(finaldim(lastdim:end)); finaldim(lastdim+1:end) = []; @@ -68,15 +79,15 @@ % non-transposed data % ------------------- res = tmpMMO.data.x(subs{:}); - if length(finaldim) == 1, finaldim(2) = 1; end; + if length(finaldim) == 1, finaldim(2) = 1; end res = reshape(res, finaldim); if obj.transposed - if finaldim(end) == 1, finaldim(end) = []; end; + if finaldim(end) == 1, finaldim(end) = []; end if length(finaldim) <= 2, res = res'; else res = reshape(res, [finaldim(1)*finaldim(2) finaldim(3)])'; res = reshape(res, [finaldim(3) finaldim(1) finaldim(2)]); - end; - end; + end + end diff --git a/functions/@mmo/sum.m b/functions/@mmo/sum.m index 696fcdc17..a8092c440 100644 --- a/functions/@mmo/sum.m +++ b/functions/@mmo/sum.m @@ -1,28 +1,39 @@ -% sum() - sum of memory mapped underlying array +% SUM - sum of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 sumval = sum(obj,dim) if nargin < 2 dim = 1; - end; + end s1 = size(obj); ss.type = '()'; @@ -32,5 +43,5 @@ if index == 1 sumval = subsref(obj, ss); else sumval = sumval + subsref(obj, ss); - end; - end; + end + end diff --git a/functions/@mmo/transpose.m b/functions/@mmo/transpose.m index b5be3f901..78dc410fb 100644 --- a/functions/@mmo/transpose.m +++ b/functions/@mmo/transpose.m @@ -2,4 +2,4 @@ res = ctranspose(obj, 0); - \ No newline at end of file + diff --git a/functions/@mmo/unitaryopp.m b/functions/@mmo/unitaryopp.m index 6ce170cff..e793a6b22 100644 --- a/functions/@mmo/unitaryopp.m +++ b/functions/@mmo/unitaryopp.m @@ -1,3 +1,5 @@ +% support function for mmo object + function obj2 = unitaryopp(f, obj1, varargin); % make new memory mapped data file (blank) @@ -5,18 +7,18 @@ newFileName = mmo.getnewfilename; data = memmapfile(obj1.dataFile, 'writable', obj1.writable, 'format', { 'single' obj1.dimensions 'x' }); fid = fopen(newFileName, 'w'); - if obj1.dimensions(end) == 1, obj1.dimensions(end) = []; end; + if obj1.dimensions(end) == 1, obj1.dimensions(end) = []; end ss.type = '()'; ss.subs(1:length(obj1.dimensions)-1) = { ':' }; for index = 1:obj1.dimensions(end) ss.subs{length(obj1.dimensions)} = index; tmpdata = f(subsref(data.Data.x, ss), varargin{:}); fwrite(fid, tmpdata, 'float'); - end; + end fclose(fid); % copy the data % ------------- obj2 = mmo(newFileName, obj1.dimensions, true, obj1.transposed); obj2 = updateWorkspace(obj2); - \ No newline at end of file + diff --git a/functions/@mmo/var.m b/functions/@mmo/var.m index 60eaff128..7ac4e6e74 100644 --- a/functions/@mmo/var.m +++ b/functions/@mmo/var.m @@ -1,31 +1,42 @@ -% var() - variance of memory mapped underlying array +% VAR - variance of memory mapped underlying array % % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 sumval = var(obj,flag,dim) if nargin < 2 flag = 0; - end; + end if nargin < 3 dim = 1; - end; + end meanvalsq = mean(obj,dim).^2; @@ -37,8 +48,8 @@ ss.subs{dim} = index; tmpdata = subsref(obj, ss); sumval = sumval + tmpdata.*tmpdata - meanvalsq; - end; + end if isempty(flag) || flag == 0 sumval = sumval/(size(obj,dim)-1); else sumval = sumval/size(obj,dim); - end; \ No newline at end of file + end diff --git a/functions/adminfunc/+up/README.txt b/functions/adminfunc/+up/README.txt deleted file mode 100644 index 58a8e7dc7..000000000 --- a/functions/adminfunc/+up/README.txt +++ /dev/null @@ -1,16 +0,0 @@ -Information for when releasing a new EEGLAB version. -This message is for EEGLAB developpers only. - -This plugins allows to perform automatic updates. -To determine the current version, type in - -[dummy eeglabVersionNumber currentReleaseDateString] = eeg_getversion; -eeglabUpdater = up.updater(eeglabVersionNumber, 'http://sccn.ucsd.edu/eeglab/updater/latest_version.php', 'EEGLAB', currentReleaseDateString); -eeglabUpdater.checkForNewVersion({'eeglab_event' 'setup'}); -eeglabUpdater - -Copy the information about the new version to - -/home/www/eeglab/updater/latestRelease.xml - -Arnaud Delorme - April 23rd, 2012 diff --git a/functions/adminfunc/+up/updater.m b/functions/adminfunc/+up/updater.m deleted file mode 100644 index c64963d9d..000000000 --- a/functions/adminfunc/+up/updater.m +++ /dev/null @@ -1,365 +0,0 @@ -classdef updater < handle - % Web-based software updater class with download and installation capabilities. - % Copyright (C) 2012 by Nima Bigdely-Shamlo, Swartz Center for Computational Neuroscience, INC, - % UCSD. - % Usage is only allowed under the same (non-commercial) license as Measure Projection toolbox. - - properties - currentVersionNumber - currentVersionReleaseDate % a string containing time and date of the current release - latestVersionNumber - releaseDate - downloadUrl - releaseNotes % text about the release. - releaseNotesUrl % The URL in which more information about the release is provided. - newMajorRevision - xmlFileUrl - lastTimeChecked % a date vector returned by clock(). - menuItemHandle = nan; % handle to the menu item that becomes visible if a new version is available. - menuItemText = 'Upgrade to the Latest Version'; % text label for the item when a newer version is available. - menuItemCallback = []; - downloadedFileName % contains file name (and path) of the downloaded latest-version file. - guiHandle - softwareName % the name of the software package to be upadted (e.g. EEGLAB) - end - - methods (Static = true) - - function writeReleaseXml(xmlFileName, versionNumber, downloadUrl, releaseNotes, releaseNotesUrl, releaseDate) - % writeReleaseXml(xmlFileName, versionNumber, downloadUrl, releaseNotes, releaseNotesUrl, releaseDate) - % use this function to make the XML file to be placed somewhere which is accessible from - % the web. - - if nargin < 4 - releaseNotes = ''; - end; - - if nargin < 5 - releaseNotesUrl = ''; - end; - - if nargin < 6 - releaseDate = datestr(now); % e.g. '0-Jan-2012 11:54:10' - end; - - % make sure version number is a string as only strings can be set as attributes. - if isnumeric(versionNumber) - versionNumber = num2str(versionNumber); - end; - - docNode = com.mathworks.xml.XMLUtils.createDocument('latestVersion'); - docRootNode = docNode.getDocumentElement; - docRootNode.setAttribute('versionNumber', versionNumber); - docRootNode.setAttribute('releaseDate', releaseDate); - docRootNode.setAttribute('downloadUrl', downloadUrl); - docRootNode.setAttribute('releaseNotes', releaseNotes); - docRootNode.setAttribute('releaseNotesUrl', releaseNotesUrl); - docRootNode.setAttribute('newMajorRevision', releaseNotesUrl); - - xmlwrite(xmlFileName, docNode); - end - - function homeDir = getHomeDirectory - if ispc - homeDir= getenv('USERPROFILE'); - else - homeDir = getenv('HOME'); - end - end; - end - - methods - function obj = updater(currentVersionNumber, xmlFileUrl, softwareName, currentVersionReleaseDate) - % obj = updater(currentVersionNumber, xmlFileUrl, softwareName, currentVersionReleaseDate) - - obj.currentVersionNumber = currentVersionNumber; - obj.xmlFileUrl = xmlFileUrl; - - if nargin > 2 - obj.softwareName = softwareName; - end; - - if nargin > 3 - obj.currentVersionReleaseDate = currentVersionReleaseDate; - end; - end - - function obj = checkForNewVersion(obj, nameValuePairs) - % nameValuePairs is a cell array of name1, value1, name 2, value 2,... send along with - % the URL request. - - if nargin < 2 - nameValuePairs = {}; - end; - - % add current version number and some other basic setup info to request URL - if ispc - osType = 'pc'; - elseif isunix - osType = 'unix'; - elseif ismac - osType = 'max'; - else - osType = 'unknown'; - end; - - nameValuePairs = [{'currentVersionNumber' num2str(obj.currentVersionNumber) 'matlabVersion' version 'OS' osType} nameValuePairs]; - - try - [xmlString successfullRead] = plugin_urlread([obj.xmlFileUrl], 'get', nameValuePairs); - catch - successfullRead = false; - end; - - if successfullRead - - % write into a temp file - temporaryFileName = tempname; - fileId = fopen(temporaryFileName, 'w'); - fprintf(fileId, '%s', xmlString); - fclose(fileId); - - % read as xml into a doc - try - docNode = xmlread(temporaryFileName); - docRootNode = docNode.getDocumentElement; - catch - successfullRead = false; - return; - end; - - % delete temporary file afterwards - delete(temporaryFileName); - - obj.latestVersionNumber = str2double(char(docRootNode.getAttribute('versionNumber'))); - obj.releaseDate = char(docRootNode.getAttribute('releaseDate')); - obj.releaseNotes = char(docRootNode.getAttribute('releaseNotes')); - obj.releaseNotesUrl = char(docRootNode.getAttribute('releaseNotesUrl')); - obj.downloadUrl = char(docRootNode.getAttribute('downloadUrl')); - obj.newMajorRevision = char(docRootNode.getAttribute('newMajorRevision')); - - obj.lastTimeChecked = clock; - - % if a menu item handle is assigned, make it visible and set its label - % appropriately (show the menu if the version is up-to-date and hide it otherwise). - if ishandle(obj.menuItemHandle) - if obj.latestVersionNumber > obj.currentVersionNumber - set(obj.menuItemHandle, 'label', [obj.menuItemText ' (' num2str(obj.latestVersionNumber) ')']); - set(obj.menuItemHandle, 'Callback', obj.menuItemCallback); - set(obj.menuItemHandle, 'visible', 'on'); - else - set(obj.menuItemHandle, 'visible', 'off'); - end; - end; - end; - end; - - function answer = newerVersionIsAvailable(obj) - answer = obj.latestVersionNumber > obj.currentVersionNumber; - end; - - function timeAGo = howLongAgoChecked(obj) % how ago was the last version check, in seconds - if isempty(obj.lastTimeChecked) - timeAGo = Inf; - else - timeAGo = etime (clock, obj.lastTimeChecked); - end; - end; - - function obj = downloadLatestVersion(obj, folderToPlace) - - if usejava('jvm') - obj.downloadedFileName = fullfile(tempdir, ['latest_version' num2str(obj.latestVersionNumber) '_' strrep(char(java.util.UUID.randomUUID),'-','_')]); - else - obj.downloadedFileName = fullfile(tempdir ,['latest_version' num2str(obj.latestVersionNumber) '_' num2str(feature('timing','cpucount'))]); - end - - % make it a bit shoter - obj.downloadedFileName = obj.downloadedFileName(1:end-30); - - % get the file part fromthe download URL and add it to the end of temp file. - % One advantage of this is to preserve file type (e.g. zip) - segmentFromUrl = obj.downloadUrl(find(obj.downloadUrl == '/', 1, 'last')+1:end); - obj.downloadedFileName = [obj.downloadedFileName '_' segmentFromUrl]; - - fprintf('Downloading the latest version (%s)....\n', num2str(obj.latestVersionNumber)); - [filestr downloadWasSucessfull] = urlwrite(obj.downloadUrl, obj.downloadedFileName); - - if downloadWasSucessfull - fprintf(['Latest-version file successfully download and is located at: ' obj.downloadedFileName '\n']); - else - fprintf('Latest-version file could not be downloaded.\n'); - end; - end; - - function obj = installDownloadedFile(obj, installFolder, goOneFolderLevelIn) - - if nargin < 2 - error(' You must specy a folder to install the latest version'); - end; - - if nargin < 3 - goOneFolderLevelIn = false; - end; - - [pathstr, name, ext] = fileparts(obj.downloadedFileName); - - temporaryFolder = tempname; - fprintf('Unpacking downloaded file...\n'); - if strcmpi(ext, '.zip') - mkdir(temporaryFolder); - unzip(obj.downloadedFileName, temporaryFolder); - elseif strcmpi(ext, '.tar') - mkdir(temporaryFolder); - untar(obj.downloadedFileName, temporaryFolder); - else - fprintf('File type in unknown and cannot be unzipped.\n'); - return; - end; - - % remove all files from installation folder - if exist(installFolder) - fprintf('Removing all files from installation folder...\n'); - rmdir(installFolder,'s'); - end; - - if goOneFolderLevelIn - listing = dir(temporaryFolder); - insideFolderName = ''; - for i=1:length(listing) - if ~(strcmp(listing(i).name, '.') || strcmp(listing(i).name, '..')) - insideFolderName = listing(i).name; - break; - end; - end; - - temporaryFolder = [temporaryFolder filesep insideFolderName]; - end; - - % copy extracted files and folder into the install (destination) folder - fprintf('Copying files from the latest version into the installation folder...\n'); - movefile(temporaryFolder, installFolder, 'f'); - - fprintf('New version (%s) is now installed. You may need to clear functions and objects or exit Matlab in order to use it.\n', num2str(obj.latestVersionNumber)); - end; - - function numberOfDays = daysCurrentVersionIsOlder(obj) - % numberOfDays = daysCurrentVersionIsOlder(obj) - % return the number of days between current version release and the latest version - % release. (empty is current release date in unknown). - - if isempty(obj.currentVersionReleaseDate) - numberOfDays = []; % cannot be calculated - else - numberOfDays = round(etime(clock, datevec(datenum(obj.currentVersionReleaseDate))) / (3600*24) ); - end; - end; - - function downloadButtonCallBack(handle, event, obj) - % close the figure - close(get(handle, 'parent')); - drawnow; - - obj.downloadLatestVersion; - end; - - function installButtonCallBack(handle, event, obj, installDirectory, goOneFolderLevelIn) - - % get the tag ifnromation from figure GUI. - guiData = get(get(handle, 'parent'), 'userdata'); - - % close the figure - close(get(handle, 'parent')); - drawnow; - - % download the file if it has not been downloaded yet. - if isempty(obj.downloadedFileName) - obj.downloadLatestVersion; - end; - - obj.installDownloadedFile(installDirectory, goOneFolderLevelIn); - - % evaulate post-install callback (text) after installation. - if ~isempty(guiData.postInstallCallbackString) - evalin('base', guiData.postInstallCallbackString); - end; - end; - - function launchGui(obj, installDirectory, goOneFolderLevelIn, backGroundColor, postInstallCallbackString) - % launchGui(obj, installDirectory, goOneFolderLevelIn, backGroundColor, postInstallCallbackString) - % installDirectory: The directory into which the new version will nbe installed. - % All files in this directory will be deleted before installation. - % - % goOneFolderLevelIn: If set to true, the folder one level inside the unpakced - % (e.g. unzipped) file will be copied into the install directory. - % This is useful if the downloaded file contains one folder which - % is the actual software to be installed. - % backGroundColor GUI background color. {optional} - % - % postInstallCallbackString commands (callback as a string) to be executed after - % installation from the GUI. {optional} - - if nargin < 3 - goOneFolderLevelIn = false; - end; - - if nargin < 5 - postInstallCallbackString = []; - end; - - updaterFolder = fileparts(which('up.updater')); - obj.guiHandle = open([updaterFolder filesep 'updater_gui.fig']); - - % save some information in tag property of the figure GUI. - guiData = struct; - guiData.postInstallCallbackString = postInstallCallbackString; - set(obj.guiHandle, 'userData', guiData); - - if nargin > 3 - warningTextHandle = findobj(obj.guiHandle, 'tag', 'warningText'); - set(obj.guiHandle, 'color', backGroundColor); - set(warningTextHandle, 'backgroundColor', backGroundColor); - end; - - % full the texbox - textBoxHandle = findobj(obj.guiHandle, 'tag', 'textBox'); - - if isempty(obj.softwareName) - textBoxTextCell = {['A newer version is available and ready for download.']}; - else - textBoxTextCell = {['A newer version of ' obj.softwareName ' is available and ready for download.']}; - end; - - currentVersionString = ['You are currently using version (' num2str(obj.currentVersionNumber) ')']; - if isempty(obj.daysCurrentVersionIsOlder) - currentVersionString = [currentVersionString '.']; - else - currentVersionString = [currentVersionString ' which is ' num2str(obj.daysCurrentVersionIsOlder) ' days older.']; - end; - - textBoxTextCell = cat(1, textBoxTextCell, currentVersionString); - - % release notes - if ~isempty(obj.releaseNotes) && ~strcmp(obj.releaseNotes, ''); - textBoxTextCell = cat(1, textBoxTextCell, '------------------------------'); - textBoxTextCell = cat(1, textBoxTextCell, 'Release Notes:'); - textBoxTextCell = cat(1, textBoxTextCell, obj.releaseNotes); - end; - - set(textBoxHandle, 'string', textBoxTextCell); - - % set callbakcs for Install and Download buttonds - downloadButtonHandle = findobj(obj.guiHandle, 'tag', 'DownloadButton'); - set(downloadButtonHandle, 'callback', {@downloadButtonCallBack, obj}); - - installButtonHandle = findobj(obj.guiHandle, 'tag', 'installButton'); - if nargin<3 - % hide install button if install directory is not provided. - set(installButtonHandle, 'visible', 'off'); - else - set(installButtonHandle, 'callback', {@installButtonCallBack, obj, installDirectory, goOneFolderLevelIn}); - end; - - end; - end -end \ No newline at end of file diff --git a/functions/adminfunc/+up/updater_gui.fig b/functions/adminfunc/+up/updater_gui.fig deleted file mode 100644 index 6a615f84b..000000000 Binary files a/functions/adminfunc/+up/updater_gui.fig and /dev/null differ diff --git a/functions/adminfunc/abouteeglab.m b/functions/adminfunc/abouteeglab.m index d7080a7f0..ff53919eb 100644 --- a/functions/adminfunc/abouteeglab.m +++ b/functions/adminfunc/abouteeglab.m @@ -1,11 +1,13 @@ -tmptmptext = strvcat(' EEGLAB 1997-2010 (compiled version)', ... +% script for compiled EEGLAB version about button + +tmptmptext = strvcat(' EEGLAB 1997-2020 (compiled version)', ... ' ', ... ' ', ... 'The EEGLAB electrophysiological data analysis software is an open source research', ... - 'project developped at the Swartz Center for Computational Neuroscience, Institute', ... + 'project developed at the Swartz Center for Computational Neuroscience, Institute', ... 'for Neural Computation at the University of California San Diego in collaboration', ... 'with The Salk Institute (La Jolla) and the CERCO laboratory (Toulouse) where part', ... - 'of the core code was developped.', ... + 'of the core code was developed.', ... ' ', ... 'EEGLAB incorporates several third party suites of functions, Fieldtrip for source ', ... 'localization, and BIOSIG for binary file import. A list of plugins is also included', ... @@ -13,7 +15,7 @@ 'information.', ... ' ', ... 'The EEGLAB software, its source code, and the source code of all additional third', ... - 'party functions it includes is protected by the GNU GPL open source license.', ... + 'party functions it includes is protected by the BSD open source license.', ... ' '); warndlg2(tmptmptext); diff --git a/functions/adminfunc/biosigpathfirst.m b/functions/adminfunc/biosigpathfirst.m new file mode 100644 index 000000000..37676c846 --- /dev/null +++ b/functions/adminfunc/biosigpathfirst.m @@ -0,0 +1,10 @@ +function biosigpathfirst +% Add BIOSIG at the beginning of the path + +str2doublepath = fileparts( which('str2double') ); +sopenpath = fileparts( which('sopen') ); +if ~strcmp(str2doublepath,sopenpath) + addpath(sopenpath,'-begin'); +end + + diff --git a/functions/adminfunc/biosigpathlast.m b/functions/adminfunc/biosigpathlast.m new file mode 100644 index 000000000..24a9d7ada --- /dev/null +++ b/functions/adminfunc/biosigpathlast.m @@ -0,0 +1,9 @@ +function biosigpathlast +% Add BIOSIG at the end of the path to avoid overloading Matlab functions + +str2doublepath = fileparts( which('str2double') ); +str2numpath = fileparts( which('str2num') ); +if ~strcmp(str2doublepath,str2numpath) + addpath(str2numpath,'-begin'); +end + diff --git a/functions/adminfunc/eeg_cache.m b/functions/adminfunc/eeg_cache.m new file mode 100644 index 000000000..66502a710 --- /dev/null +++ b/functions/adminfunc/eeg_cache.m @@ -0,0 +1,79 @@ +% EEG_CACHE - Store data in cache with hashcode +% +% >> [cache data] = eeg_cache(cache, hashcode, data); +% +% Inputs: +% cache - Cell array containing cached data +% hashcode - MD5 hashcode +% +% Optional input: +% data - This can be anything +% +% Outputs: +% cache - Updated cache information +% data - Data corresponding to the hash code. If the hash code +% is not found, this output is empty. +% +% Note: this script checks if the cache variable is larger than option_cachesize +% If it is the case, elements are removed until an acceptable size is +% reached. +% +% Examples +% cache = eeg_cache([], 'dyufisf8da0df', 3); % store 3 with hashcode dyufisf8da0df +% [cache data] = eeg_cache(cache, 'dyufisf8da0df'); % retrieve 3 +% +% Authors: Arnaud Delorme, SCCN, INC, UCSD, 2015 + +% Copyright (C) Arnaud Delorme, SCCN, INC, UCSD, June 07, 2007, arno@sccn.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 [cache data] = eeg_cache(cache, hashcode, data) + +eeglab_options; + +ind = []; +if ~isempty(cache) + allHashCodes = { cache.hashcode }; + maxlen = max(max(cellfun(@length, allHashCodes)), length(hashcode)); + ind = find(strncmp(hashcode, allHashCodes, maxlen)); +end + +if isempty(ind) + if nargin > 2 + cache(end+1).hashcode = hashcode; + cache(end ).data = data; + + % make sure the cache is not too large + while getfield(whos('cache'), 'bytes') > option_cachesize*1000000 + cache(1) = []; + end + else + data = []; + end +else + data = cache(ind).data; +end diff --git a/functions/adminfunc/eeg_checkchanlocs.m b/functions/adminfunc/eeg_checkchanlocs.m index 55fedf191..ed825bb9e 100644 --- a/functions/adminfunc/eeg_checkchanlocs.m +++ b/functions/adminfunc/eeg_checkchanlocs.m @@ -1,9 +1,9 @@ -% eeg_checkchanlocs() - Check the consistency of the channel locations structure +% EEG_CHECKCHANLOCS - Check the consistency of the channel locations structure % of an EEGLAB dataset. % % Usage: -% >> EEG = eeg_checkchanlocs( EEG, 'key1', value1, 'key2', value2, ... ); -% >> [chanlocs chaninfo] = eeg_checkchanlocs( chanlocs, chaninfo, 'key1', value1, 'key2', value2, ... ); +% >> EEG = eeg_checkchanlocs(EEG); +% >> [chanlocs chaninfo] = eeg_checkchanlocs( chanlocs, chaninfo); % % Inputs: % EEG - EEG dataset @@ -20,19 +20,30 @@ % Copyright (C) SCCN/INC/UCSD, March 2, 2011, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % Hey Arno -- this is a quick fix to make an analysis work for Makoto % I think the old version had a bug... @@ -42,31 +53,73 @@ if nargin < 1 help eeg_checkchanlocs; return; -end; +end if nargin < 2 chaninfo = []; -end; +end processingEEGstruct = 0; if isfield(chans, 'data') processingEEGstruct = 1; tmpEEG = chans; - chans = tmpEEG.chanlocs; - chaninfo = tmpEEG.chaninfo; -end; + [chans, chaninfo] = insertchans(tmpEEG.chanlocs, tmpEEG.chaninfo); -if ~isfield(chans, 'datachan') - [chanedit,dummy,complicated] = insertchans(chans, chaninfo); -else + % force Nosedir to +X (done here because of DIPFIT) + % ------------------- + if isfield(tmpEEG.chaninfo, 'nosedir') + if ~strcmpi(tmpEEG.chaninfo.nosedir, '+x') && all(isfield(tmpEEG.chanlocs,{'X','Y','theta','sph_theta'})) + disp(['Note for expert users: Nose direction is now set from ''' upper(tmpEEG.chaninfo.nosedir) ''' to default +X in EEG.chanlocs']); + [~, chaninfo, chans] = eeg_checkchanlocs(tmpEEG.chanlocs, tmpEEG.chaninfo); % Merge all channels for rotation (FID and data channels) + if strcmpi(chaninfo.nosedir, '+y') + rotate = 270; + elseif strcmpi(chaninfo.nosedir, '-x') + rotate = 180; + else + rotate = 90; + end + for index = 1:length(chans) + rotategrad = rotate/180*pi; + coord = (chans(index).Y + chans(index).X*sqrt(-1))*exp(sqrt(-1)*-rotategrad); + chans(index).Y = real(coord); + chans(index).X = imag(coord); + + if ~isempty(chans(index).theta) + chans(index).theta = chans(index).theta -rotate; + chans(index).sph_theta = chans(index).sph_theta+rotate; + if chans(index).theta <-180, chans(index).theta =chans(index).theta +360; end + if chans(index).sph_theta>180 , chans(index).sph_theta=chans(index).sph_theta-360; end + end + end + + if isfield(tmpEEG, 'dipfit') + if isfield(tmpEEG.dipfit, 'coord_transform') + if isempty(tmpEEG.dipfit.coord_transform) + tmpEEG.dipfit.coord_transform = [0 0 0 0 0 0 1 1 1]; + end + tmpEEG.dipfit.coord_transform(6) = tmpEEG.dipfit.coord_transform(6)+rotategrad; + end + end + + chaninfo.originalnosedir = chaninfo.nosedir; + chaninfo.nosedir = '+X'; + end + end chanedit = chans; complicated = true; -end; +else + if ~isfield(chans, 'datachan') + [chanedit,dummy,complicated] = insertchans(chans, chaninfo); + else + chanedit = chans; + complicated = true; + end +end nosevals = { '+X' '-X' '+Y' '-Y' }; -if ~isfield(chaninfo, 'plotrad'), chaninfo.plotrad = []; end; -if ~isfield(chaninfo, 'shrink'), chaninfo.shrink = []; end; -if ~isfield(chaninfo, 'nosedir'), chaninfo.nosedir = nosevals{1}; end; +if ~isfield(chaninfo, 'plotrad'), chaninfo.plotrad = []; end +if ~isfield(chaninfo, 'shrink'), chaninfo.shrink = []; end +if ~isfield(chaninfo, 'nosedir'), chaninfo.nosedir = nosevals{1}; end % handles deprecated fields % ------------------------- @@ -74,17 +127,17 @@ if isfield(chanedit, 'plotrad'), plotrad = chanedit(1).plotrad; chanedit = rmfield(chanedit, 'plotrad'); - if isstr(plotrad) & ~isempty(str2num(plotrad)), plotrad = str2num(plotrad); end; + if ischar(plotrad) && ~isempty(str2num(plotrad)), plotrad = str2num(plotrad); end chaninfo.plotrad = plotrad; -end; +end if isfield(chanedit, 'shrink') && ~isempty(chanedit(1).shrink) shrinkorskirt = 1; - if ~isstr(chanedit(1).shrink) + if ~ischar(chanedit(1).shrink) plotrad = 0.5/(1-chanedit(1).shrink); % convert old values - end; + end chanedit = rmfield(chanedit, 'shrink'); chaninfo.plotrad = plotrad; -end; +end % set non-existent fields to [] % ----------------------------- @@ -101,24 +154,30 @@ else for indchan = 1:length(chanedit) chanedit = setfield(chanedit, {indchan}, fields{index}, ''); - end; - end; + end + end else % existing fields % --------------- allvals = {chanedit.(fields{index})}; + if isnumeric(allvals{1}) && any(cellfun(@(x)~isempty(x) & all(isnan(x)), allvals)) + posNaNs = find(cellfun(@(x)~isempty(x) & all(isnan(x)), allvals)); + for iPos = 1:length(posNaNs) + chanedit = setfield(chanedit, {posNaNs(iPos)}, fields{index}, []); + end + end if strcmpi(fieldtype{index}, 'num') if ~all(cellfun('isclass',allvals,'double')) numok = cellfun(@isnumeric, allvals); if any(numok == 0) for indConvert = find(numok == 0) chanedit = setfield(chanedit, {indConvert}, fields{index}, []); - end; - end; + end + end end else strok = cellfun('isclass', allvals,'char'); - if strcmpi(fields{index}, 'labels'), prefix = 'E'; else prefix = ''; end; + if strcmpi(fields{index}, 'labels'), prefix = 'E'; else prefix = ''; end if any(strok == 0) for indConvert = find(strok == 0) try @@ -126,32 +185,44 @@ chanedit = setfield(chanedit, {indConvert}, fields{index}, strval); catch chanedit = setfield(chanedit, {indConvert}, fields{index}, ''); - end; - end; - end; - end; - end; - end; -end; + end + end + end + end + end + end +end + if ~isequal(fieldnames(chanedit)',fields) try chanedit = orderfields(chanedit, fields); - catch, end; + catch, end end -% check if duplicate channel label -% -------------------------------- + +% check channel labels if isfield(chanedit, 'labels') + % prefix (EDF format specification)? + if strfind([chanedit.labels], 'EEG') % `contains() is not back compatible + chanprefixes = {'EEG-', 'EEG ', 'EEG'}; % order matters + tmp = {chanedit.labels}; + if sum(~isnan(str2double( strrep(tmp, 'EEG', '')))) < 30 % more than 30 numerical channels, i.e., EEG001, do nothing + disp('Detected/removing ''EEG'' prefix from channel labels') + for idx = 1:length(chanprefixes) + tmp = strrep(tmp, chanprefixes(idx), ''); + end + [chanedit.labels] = deal(tmp{:}); + end + end + + % duplicate labels? tmp = sort({chanedit.labels}); if any(strcmp(tmp(1:end-1),tmp(2:end))) disp('Warning: some channels have the same label'); end -end; - -% check for empty channel label -% ----------------------------- -if isfield(chanedit, 'labels') - indEmpty = find(cellfun(@isempty, {chanedit.labels})); + + % empty labels? + indEmpty = find(cellfun(@isempty, {chanedit.labels})); if ~isempty(indEmpty) tmpWarning = warning('backtrace'); warning backtrace off; @@ -159,25 +230,47 @@ warning(tmpWarning); for index = indEmpty chanedit(index).labels = sprintf('E%d', index); - end; - end; -end; + end + end + + % handle MEG + if ~isfield(chaninfo, 'topoplot') + if ~isempty(strfind([chanedit(1).labels], 'MLC11')) || (isfield(chanedit, 'type') && ~isempty(strfind(chanedit(1).type, 'meg'))) + disp('MEG data detected and topoplot options not set, so setting them in EEG.chaninfo') + chaninfo.topoplot = { 'conv' 'on' 'headrad' 0.3 }; + end + end +end % remove fields % ------------- -if isfield(chanedit, 'sph_phi_besa' ), chanedit = rmfield(chanedit, 'sph_phi_besa'); end; -if isfield(chanedit, 'sph_theta_besa'), chanedit = rmfield(chanedit, 'sph_theta_besa'); end; +if isfield(chanedit, 'sph_phi_besa' ), chanedit = rmfield(chanedit, 'sph_phi_besa'); end +if isfield(chanedit, 'sph_theta_besa'), chanedit = rmfield(chanedit, 'sph_theta_besa'); end + +% Check if some channels need conversion +% -------------------------------------- +chanX = cellfun('isempty',{ chanedit.X }); +chanTheta = cellfun('isempty',{ chanedit.theta }); +chanSphTheta = cellfun('isempty',{ chanedit.sph_theta }); +if any(~chanX & chanTheta) || any(~chanSphTheta & chanTheta) || any(~chanX & chanSphTheta) + try + % convert them all + chanedit = convertlocs(chanedit,'auto'); + catch + disp('eeg_checkchanlocs: Unable to convert electrode locations between coordinate systems'); + end +end % reconstruct the chans structure % ------------------------------- if complicated - [chans chaninfo.nodatchans] = getnodatchan( chanedit ); - if ~isfield(chaninfo, 'nodatchans'), chaninfo.nodatchans = []; end; + [chans, chaninfo.nodatchans] = getnodatchan( chanedit ); + if ~isfield(chaninfo, 'nodatchans'), chaninfo.nodatchans = []; end if isempty(chanedit) for iField = 1:length(fields) chanedit = setfield(chanedit, fields{iField}, []); - end; - end; + end + end else chans = rmfield(chanedit,'datachan'); chaninfo.nodatchans = []; @@ -187,7 +280,7 @@ tmpEEG.chanlocs = chans; tmpEEG.chaninfo = chaninfo; chans = tmpEEG; -end; +end % --------------------------------------------- % separate data channels from non-data channels @@ -200,13 +293,13 @@ chans = rmfield(chans(~fids),'datachan'); else fids = []; -end; +end % ---------------------------------------- % fuse data channels and non-data channels % ---------------------------------------- function [chans, chaninfo,complicated] = insertchans(chans, chaninfo, nchans) -if nargin < 3, nchans = length(chans); end; +if nargin < 3, nchans = length(chans); end [chans.datachan] = deal(1); complicated = false; % whether we need complicated treatment of datachans & co further down the road..... @@ -217,10 +310,10 @@ complicated = true; end end -if length(chans) > nchans & nchans ~= 0 % reference at the end of the structure +if length(chans) > nchans && nchans ~= 0 % reference at the end of the structure chans(end).datachan = 0; complicated = true; -end; +end if isfield(chaninfo, 'nodatchans') if ~isempty(chaninfo.nodatchans) && isstruct(chaninfo.nodatchans) chanlen = length(chans); @@ -229,10 +322,10 @@ ind = chanlen+index; for f = 1:length( fields ) chans = setfield(chans, { ind }, fields{f}, getfield( chaninfo.nodatchans, { index }, fields{f})); - end; + end chans(ind).datachan = 0; complicated = true; - end; + end chaninfo = rmfield(chaninfo, 'nodatchans'); % put these channels first @@ -240,5 +333,5 @@ % tmp = chans(chanlen+1:end); % chans(length(tmp)+1:end) = chans(1:end-length(tmp)); % chans(1:length(tmp)) = tmp; - end; -end; + end +end diff --git a/functions/adminfunc/eeg_checkset.m b/functions/adminfunc/eeg_checkset.m index b7df880d8..e7a184c00 100644 --- a/functions/adminfunc/eeg_checkset.m +++ b/functions/adminfunc/eeg_checkset.m @@ -1,4 +1,4 @@ -% eeg_checkset() - check the consistency of the fields of an EEG dataset +% EEG_CHECKSET - check the consistency of the fields of an EEG dataset % Also: See EEG dataset structure field descriptions below. % % Usage: >> [EEGOUT,changes] = eeg_checkset(EEG); % perform all checks @@ -14,7 +14,7 @@ % 'epochconsist' - if EEG contains several datasets, check whether they have % identical epoch lengths and time limits. % 'chanconsist' - if EEG contains several datasets, check whether they have -% the same number of channela and channel labels. +% the same number of channels and channel labels. % 'data' - check whether EEG contains data (EEG.data) % 'loaddata' - load data array (if necessary) % 'savedata' - save data array (if necessary - see EEG.saved below) @@ -29,7 +29,8 @@ % 'chanlocsize' - check the EEG.chanlocs structure length; show warning if % necessary. % 'chanlocs_homogeneous' - check whether EEG contains consistent channel -% information; if not, correct it. +% information; if not, correct it.This option +% calls eeg_checkchanlocs. % 'eventconsistency' - check whether EEG.event information are consistent; % rebuild event* subfields of the 'EEG.epoch' structure % (can be time consuming). @@ -55,7 +56,7 @@ % EEG.xmin - epoch start latency|time (in sec. relative to the % time-locking event at time 0) % EEG.xmax - epoch end latency|time (in seconds) -% EEG.times - vector of latencies|times in seconds (one per time point) +% EEG.times - vector of latencies|times in milliseconds (one per time point) % EEG.ref - ['common'|'averef'|integer] reference channel type or number % EEG.history - cell array of ascii pop-window commands that created % or modified the dataset @@ -76,7 +77,7 @@ % (before channel rejection) % EEG.chaninfo - structure containing additional channel info % EEG.ref - type of channel reference ('common'|'averef'|+/-int] -% EEG.splinefile - location of the spline file used by headplot() to plot +% EEG.splinefile - location of the spline file used by HEADPLOT to plot % data scalp maps in 3-D % % The event and epoch sub-structures: @@ -96,10 +97,10 @@ % EEG.icawinv - inverse (ICA) weight matrix. Columns gives the projected % topographies of the components to the electrodes. % EEG.icaact - ICA activations matrix (components, frames, epochs) -% Note: [] here means that 'compute_ica' option has bee set +% Note: [] here means that 'compute_ica' option has been set % to 0 under 'File > Memory options' In this case, % component activations are computed only as needed. -% EEG.icasplinefile - location of the spline file used by headplot() to plot +% EEG.icasplinefile - location of the spline file used by HEADPLOT to plot % component scalp maps in 3-D % EEG.chaninfo.icachansind - indices of channels used in the ICA decomposition % EEG.dipfit - array of structures containing component map dipole models @@ -108,6 +109,7 @@ % EEG.subject - studyset subject code % EEG.group - studyset group code % EEG.condition - studyset experimental condition code +% EEG.run - studyset run number % EEG.session - studyset session number % % Variables used for manual and semi-automatic data rejection: @@ -130,29 +132,40 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % -% See also: eeglab() +% See also: EEGLAB % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license -ad % 01-26-02 chandeg events and trial condition format -ad % 01-27-02 debug when trial condition is empty -ad % 02-15-02 remove icawinv recompute for pop_epoch -ad & ja -% 02-16-02 remove last modification and test icawinv separatelly -ad +% 02-16-02 remove last modification and test icawinv separately -ad % 02-16-02 empty event and epoch check -ad % 03-07-02 add the eeglab options -ad % 03-07-02 corrected typos and rate/point calculation -ad & ja @@ -160,7 +173,7 @@ % 03-15-02 add checking of ICA and epochs with pop_up windows -ad % 03-27-02 recorrected rate/point calculation -ad & sm -function [EEG, res] = eeg_checkset( EEG, varargin ); +function [EEGFINAL, res] = eeg_checkset( EEG, varargin ) msg = ''; res = 'no'; com = sprintf('EEG = eeg_checkset( EEG );'); @@ -168,28 +181,35 @@ if nargin < 1 help eeg_checkset; return; -end; +end -if isempty(EEG), return; end; -if ~isfield(EEG, 'data'), return; end; +EEGFINAL = EEG; +warning backtrace off +if isempty(EEG), return; end +if ~isfield(EEG, 'data'), return; end % checking multiple datasets % -------------------------- if length(EEG) > 1 + + if length(EEG) > 5000 + disp('Too many datasets, abording check') + return; + end if nargin > 1 switch varargin{1} - case 'epochconsist', % test epoch consistency + case 'epochconsist' % test epoch consistency % ---------------------- res = 'no'; datasettype = unique_bc( [ EEG.trials ] ); - if datasettype(1) == 1 & length(datasettype) == 1, return; % continuous data + if datasettype(1) == 1 && length(datasettype) == 1, return; % continuous data elseif datasettype(1) == 1, return; % continuous and epoch data - end; + end allpnts = unique_bc( [ EEG.pnts ] ); allxmin = unique_bc( [ EEG.xmin ] ); - if length(allpnts) == 1 & length(allxmin) == 1, res = 'yes'; end; + if length(allpnts) == 1 && length(allxmin) == 1, res = 'yes'; end return; case 'chanconsist' % test channel number and name consistency @@ -197,37 +217,42 @@ res = 'yes'; chanlen = unique_bc( [ EEG.nbchan ] ); anyempty = unique_bc( cellfun( 'isempty', { EEG.chanlocs }) ); - if length(chanlen) == 1 & all(anyempty == 0) + if length(chanlen) == 1 && all(anyempty == 0) tmpchanlocs = EEG(1).chanlocs; channame1 = { tmpchanlocs.labels }; for i = 2:length(EEG) tmpchanlocs = EEG(i).chanlocs; channame2 = { tmpchanlocs.labels }; - if length(intersect(channame1, channame2)) ~= length(channame1), res = 'no'; end; - end; + if length(intersect(channame1, channame2)) ~= length(channame1), res = 'no'; end + end else res = 'no'; - end; + end + + % Field 'datachan in 'urchanlocs' is removed, if exist + if isfield(EEG, 'urchanlocs') && ~all(cellfun(@isempty,{EEG.urchanlocs})) && isfield([EEG.urchanlocs], 'datachan') + [EEG.urchanlocs] = deal(rmfield([EEG.urchanlocs], 'datachan')); + end return; case 'icaconsist' % test ICA decomposition consistency % ---------------------------------- res = 'yes'; anyempty = unique_bc( cellfun( 'isempty', { EEG.icaweights }) ); - if length(anyempty) == 1 & anyempty(1) == 0 + if length(anyempty) == 1 && anyempty(1) == 0 ica1 = EEG(1).icawinv; for i = 2:length(EEG) if ~isequal(EEG(1).icawinv, EEG(i).icawinv) res = 'no'; - end; - end; + end + end else res = 'no'; - end; + end return; - end; - end; + end + end -end; +end % reading these option take time because % of disk access @@ -248,34 +273,35 @@ for index = 1:length( varargin ) switch varargin{ index } case 'data',; % already done at the top - case 'contdata',; + case 'contdata', if EEG.trials > 1 errordlg2(strvcat('Error: function only works on continuous data'), 'Error'); return; - end; + end case 'ica', if isempty(EEG.icaweights) errordlg2(strvcat('Error: no ICA decomposition. use menu "Tools > Run ICA" first.'), 'Error'); return; - end; + end case 'epoch', if EEG.trials == 1 errordlg2(strvcat('Extract epochs before running that function', 'Use Tools > Extract epochs'), 'Error'); return - end; + end case 'besa', if ~isfield(EEG, 'sources') errordlg2(strvcat('No dipole information', '1) Export component maps: Tools > Localize ... BESA > Export ...' ... , '2) Run BESA to localize the equivalent dipoles', ... '3) Import the BESA dipoles: Tools > Localize ... BESA > Import ...'), 'Error'); return - end; + end case 'event', if isempty(EEG.event) errordlg2(strvcat('Requires events. You need to add events first.', ... - 'Use "File > Import event info" or "File > Import epoch info"'), 'Error'); + 'Use "File > Import event info" or "File > Import epoch info"', ... + 'Install plugin VidEd to manually add events as you scroll the data.' ), 'Error'); return; - end; + end case 'chanloc', tmplocs = EEG.chanlocs; if isempty(tmplocs) || ~isfield(tmplocs, 'theta') || all(cellfun('isempty', { tmplocs.theta })) @@ -283,19 +309,20 @@ 'Enter the channel file name via "Edit > Edit dataset info".', ... 'For channel file format, see ''>> help readlocs'' from the command line.'), 'Error'); return; - end; - case 'chanlocs_homogeneous', + end + case 'chanlocs_homogeneous', tmplocs = EEG.chanlocs; if isempty(tmplocs) || ~isfield(tmplocs, 'theta') || all(cellfun('isempty', { tmplocs.theta })) errordlg2( strvcat('This functionality requires channel location information.', ... 'Enter the channel file name via "Edit > Edit dataset info".', ... 'For channel file format, see ''>> help readlocs'' from the command line.'), 'Error'); return; - end; + end if ~isfield(EEG.chanlocs, 'X') || isempty(EEG.chanlocs(1).X) - EEG.chanlocs = convertlocs(EEG.chanlocs, 'topo2all'); - res = [ inputname(1) ' = eeg_checkset(' inputname(1) ', ''chanlocs_homogeneous'' ); ' ]; - end; + EEG = eeg_checkchanlocs(EEG); + % EEG.chanlocs = convertlocs(EEG.chanlocs, 'topo2all'); + res = ['EEG = eeg_checkset(EEG, ''chanlocs_homogeneous''); ' ]; + end case 'chanlocsize', if ~isempty(EEG.chanlocs) if length(EEG.chanlocs) > EEG.nbchan @@ -303,8 +330,8 @@ 'data channels. EEGLAB will consider the last electrode to be the', ... 'common reference channel. If this is not the case, remove the', ... 'extra channel'), 'Warning', 'Ok', 'Ok'); - end; - end; + end + end case 'makeur', if ~isempty(EEG.event) if isfield(EEG.event, 'urevent'), @@ -312,15 +339,15 @@ disp('eeg_checkset note: re-creating the original event table (EEG.urevent)'); else disp('eeg_checkset note: creating the original event table (EEG.urevent)'); - end; + end EEG.urevent = EEG.event; for index = 1:length(EEG.event) EEG.event(index).urevent = index; - end; - end; + end + end case 'checkur', if ~isempty(EEG.event) - if isfield(EEG.event, 'urevent') & ~isempty(EEG.urevent) + if isfield(EEG.event, 'urevent') && ~isempty(EEG.urevent) urlatencies = [ EEG.urevent.latency ]; [newlat tmpind] = sort(urlatencies); if ~isequal(newlat, urlatencies) @@ -328,50 +355,66 @@ [tmp tmpind2] = sort(tmpind); for index = 1:length(EEG.event) EEG.event(index).urevent = tmpind2(EEG.event(index).urevent); - end; - end; - end; - end; + end + end + end + end case 'eventconsistency', [EEG res] = eeg_checkset(EEG); - if isempty(EEG.event), return; end; + if isempty(EEG.event), return; end % check events (slow) % ------------ if isfield(EEG.event, 'type') eventInds = arrayfun(@(x)isempty(x.type), EEG.event); if any(eventInds) + eventInds = find(eventInds); + eventInds = eventInds(:)'; % make row vector if all(arrayfun(@(x)isnumeric(x.type), EEG.event)) - for ind = find(eventInds), EEG.event(ind).type = NaN; end; - else for ind = find(eventInds), EEG.event(ind).type = 'empty'; end; - end; - end; + for ind = eventInds, EEG.event(ind).type = NaN; end + else for ind = eventInds, EEG.event(ind).type = 'empty'; end + end + end if ~all(arrayfun(@(x)ischar(x.type), EEG.event)) && ~all(arrayfun(@(x)isnumeric(x.type), EEG.event)) disp('Warning: converting all event types to strings'); for ind = 1:length(EEG.event) EEG.event(ind).type = num2str(EEG.event(ind).type); - end; + end EEG = eeg_checkset(EEG, 'eventconsistency'); - end; + end - end; + end + + % Removing events with NaN latency + % -------------------------------- + if isfield(EEG.event, 'latency') + nanindex = find(isnan([ EEG.event.latency ])); + if ~isempty(nanindex) + EEG.event(nanindex) = []; + trialtext = ''; + for inan = 1:length(nanindex) + trialstext = [trialtext ' ' num2str(nanindex(inan))]; + end + disp(sprintf(['eeg_checkset: Event(s) with NaN latency were deleted \nDeleted event index(es):[' trialstext ']'])); + end + end % remove the events which latency are out of boundary % --------------------------------------------------- if isfield(EEG.event, 'latency') - if isfield(EEG.event, 'type') && ischar(EEG.event(1).type) - if strcmpi(EEG.event(1).type, 'boundary') & isfield(EEG.event, 'duration') + if isfield(EEG.event, 'type') + if eeg_isboundary(EEG.event(1)) && isfield(EEG.event, 'duration') if EEG.event(1).duration < 1 EEG.event(1) = []; - elseif EEG.event(1).latency > 0 & EEG.event(1).latency < 1 + elseif EEG.event(1).latency > 0 && EEG.event(1).latency < 1 EEG.event(1).latency = 0.5; - end; - end; - end; + end + end + end try, tmpevent = EEG.event; alllatencies = [ tmpevent.latency ]; catch, error('Checkset: error empty latency entry for new events added by user'); - end; + end I1 = find(alllatencies < 0.5); I2 = find(alllatencies > EEG.pnts*EEG.trials+1); % The addition of 1 was included % because, if data epochs are extracted from -1 to @@ -382,9 +425,9 @@ fprintf('eeg_checkset warning: %d/%d events had out-of-bounds latencies and were removed\n', ... length(I1) + length(I2), length(EEG.event)); EEG.event(union(I1, I2)) = []; - end; - end; - if isempty(EEG.event), return; end; + end + end + if isempty(EEG.event), return; end % save information for non latency fields updates % ----------------------------------------------- @@ -393,116 +436,77 @@ % remove fields with empty epochs % ------------------------------- removeevent = []; - try, tmpevent = EEG.event; allepochs = [ tmpevent.epoch ]; + try + tmpevent = EEG.event; + allepochs = [ tmpevent.epoch ]; removeevent = find( allepochs < 1 | allepochs > EEG.trials); if ~isempty(removeevent) disp([ 'eeg_checkset warning: ' int2str(length(removeevent)) ' event had invalid epoch numbers and were removed']); - end; - catch, + end + catch for indexevent = 1:length(EEG.event) if isempty( EEG.event(indexevent).epoch ) || ~isnumeric(EEG.event(indexevent).epoch) ... - | EEG.event(indexevent).epoch < 1 || EEG.event(indexevent).epoch > EEG.trials + || EEG.event(indexevent).epoch < 1 || EEG.event(indexevent).epoch > EEG.trials removeevent = [removeevent indexevent]; disp([ 'eeg_checkset warning: event ' int2str(indexevent) ' has an invalid epoch number: removed']); - end; - end; - end; + end + end + end EEG.event(removeevent) = []; - tmpevent = EEG.event; - allepochs = [ tmpevent.epoch ]; - - % uniformize fields content for the different epochs - % -------------------------------------------------- - % THIS WAS REMOVED SINCE SOME FIELDS ARE ASSOCIATED WITH THE EVENT AND NOT WITH THE EPOCH - % I PUT IT BACK, BUT IT DOES NOT ERASE NON-EMPTY VALUES - difffield = fieldnames(EEG.event); - difffield = difffield(~(strcmp(difffield,'latency')|strcmp(difffield,'epoch')|strcmp(difffield,'type'))); - for index = 1:length(difffield) - tmpevent = EEG.event; - allvalues = { tmpevent.(difffield{index}) }; - try - valempt = cellfun('isempty', allvalues); - catch - valempt = mycellfun('isempty', allvalues); - end; - arraytmpinfo = cell(1,EEG.trials); - - % spetial case of duration - % ------------------------ - if strcmp( difffield{index}, 'duration') - if any(valempt) - fprintf(['eeg_checkset: found empty values for field ''' difffield{index} ... - ''' (filling with 0)\n']); - end; - for indexevent = find(valempt) - EEG.event(indexevent).duration = 0; - end; - else - - % get the field content - % --------------------- - indexevent = find(~valempt); - arraytmpinfo(allepochs(indexevent)) = allvalues(indexevent); - - % uniformize content for all epochs - % --------------------------------- - indexevent = find(valempt); - tmpevent = EEG.event; - [tmpevent(indexevent).(difffield{index})] = arraytmpinfo{allepochs(indexevent)}; - EEG.event = tmpevent; - if any(valempt) - fprintf(['eeg_checkset: found empty values for field ''' difffield{index} '''\n']); - fprintf([' filling with values of other events in the same epochs\n']); - end; - end; - end; - end; - if isempty(EEG.event), return; end; + end + if isempty(EEG.event), return; end + + % Duration set to 0 if empty + % -------------------------- + if isfield(EEG.event, 'duration') + emptyDur = cellfun(@isempty, { EEG.event.duration }); + if any(emptyDur) + for indexevent = find(emptyDur) + EEG.event(indexevent).duration = 0; + end + end + end % uniformize fields (str or int) if necessary % ------------------------------------------- fnames = fieldnames(EEG.event); for fidx = 1:length(fnames) fname = fnames{fidx}; - tmpevent = EEG.event; - allvalues = { tmpevent.(fname) }; - try - % find indices of numeric values among values of this event property - valreal = ~cellfun('isclass', allvalues, 'char'); - catch - valreal = mycellfun('isclass', allvalues, 'double'); - end; - - format = 'ok'; - if ~all(valreal) % all valreal ok - format = 'str'; - if all(valreal == 0) % all valreal=0 ok - format = 'ok'; - end; - end; - if strcmp(format, 'str') - fprintf('eeg_checkset note: value format of event field ''%s'' made uniform\n', fname); - % get the field content - % --------------------- - for indexevent = 1:length(EEG.event) - if valreal(indexevent) - EEG.event = setfield(EEG.event, { indexevent }, fname, num2str(allvalues{indexevent}) ); - end; - end; - end; - end; + if ~strcmpi(fname, 'mffkeys') && ~strcmpi(fname, 'mffkeysbackup') + tmpevent = EEG.event; + allvalues = { tmpevent.(fname) }; + try + % find indices of numeric values among values of this event property + valreal = ~cellfun('isclass', allvalues, 'char'); + catch + valreal = mycellfun('isclass', allvalues, 'double'); + end + + format = 'ok'; + if ~all(valreal) % all valreal ok + format = 'str'; + if all(valreal == 0) % all valreal=0 ok + format = 'ok'; + end + end + if strcmp(format, 'str') + fprintf('eeg_checkset note: event field format ''%s'' made uniform\n', fname); + allvalues = cellfun(@num2str, allvalues, 'uniformoutput', false); + [EEG.event(valreal).(fname)] = deal(allvalues{find(valreal)}); + end + end + end % check boundary events % --------------------- tmpevent = EEG.event; if isfield(tmpevent, 'type') && ~isnumeric(tmpevent(1).type) - allEventTypes = { tmpevent.type }; - boundsInd = strmatch('boundary', allEventTypes); - if ~isempty(boundsInd), + boundsInd = eeg_findboundaries(EEG); + if ~isempty(boundsInd) bounds = [ tmpevent(boundsInd).latency ]; % remove last event if necessary - if EEG.trials==1;%this if block added by James Desjardins (Jan 13th, 2014) - if round(bounds(end)-0.5+1) >= size(EEG.data,2), EEG.event(boundsInd(end)) = []; bounds(end) = []; end; % remove final boundary if any + if EEG.trials==1 %this if block added by James Desjardins (Jan 13th, 2014) + if round(bounds(end)-0.5) > size(EEG.data,2), EEG.event(boundsInd(end)) = []; bounds(end) = []; end; % remove final boundary if any end % The first boundary below need to be kept for % urevent latency calculation @@ -510,14 +514,16 @@ indDoublet = find(bounds(2:end)-bounds(1:end-1)==0); if ~isempty(indDoublet) disp('Warning: duplicate boundary event removed'); - for indBound = 1:length(indDoublet) - EEG.event(boundsInd(indDoublet(indBound)+1)).duration = EEG.event(boundsInd(indDoublet(indBound)+1)).duration+EEG.event(boundsInd(indDoublet(indBound))).duration; - end; + if isfield(EEG.event, 'duration') + for indBound = 1:length(indDoublet) + EEG.event(boundsInd(indDoublet(indBound)+1)).duration = EEG.event(boundsInd(indDoublet(indBound)+1)).duration+EEG.event(boundsInd(indDoublet(indBound))).duration; + end + end EEG.event(boundsInd(indDoublet)) = []; - end; - end; - end; - if isempty(EEG.event), return; end; + end + end + end + if isempty(EEG.event), return; end % check that numeric format is double (Matlab 7) % ----------------------------------- @@ -529,42 +535,44 @@ for indexevent = 1:length(EEG.event) tmpval = getfield(EEG.event, { indexevent }, allfields{index} ); EEG.event = setfield(EEG.event, { indexevent }, allfields{index}, double(tmpval)); - end; - end; - end; - end; + end + end + end + end % check duration field, replace empty by 0 % ---------------------------------------- if isfield(EEG.event, 'duration') tmpevent = EEG.event; - try, valempt = cellfun('isempty' , { tmpevent.duration }); - catch, valempt = mycellfun('isempty', { tmpevent.duration }); - end; - if any(valempt), + try + valempt = cellfun('isempty' , { tmpevent.duration }); + catch + valempt = mycellfun('isempty', { tmpevent.duration }); + end + if any(valempt) for index = find(valempt) EEG.event(index).duration = 0; - end; - end; - end; + end + end + end % resort events % ------------- if isfield(EEG.event, 'latency') - try, + try if isfield(EEG.event, 'epoch') TMPEEG = pop_editeventvals(EEG, 'sort', { 'epoch' 0 'latency' 0 }); else TMPEEG = pop_editeventvals(EEG, 'sort', { 'latency' 0 }); - end; + end if ~isequal(TMPEEG.event, EEG.event) EEG = TMPEEG; disp('Event resorted by increasing latencies.'); - end; - catch, + end + catch disp('eeg_checkset: problem when attempting to resort event latencies.'); - end; - end; + end + end % check latency of first event % ---------------------------- @@ -572,14 +580,14 @@ if isfield(EEG.event, 'latency') if EEG.event(1).latency < 0.5 EEG.event(1).latency = 0.5; - end; - end; - end; + end + end + end % build epoch structure % --------------------- try, - if EEG.trials > 1 & ~isempty(EEG.event) + if EEG.trials > 1 && ~isempty(EEG.event) % erase existing event-related fields % ------------------------------ if ~isfield(EEG,'epoch') @@ -639,16 +647,16 @@ [tmpepoch.(['event' fname])] = destdata{:}; EEG.epoch = tmpepoch; end - end; + end catch, errordlg2(['Warning: minor problem encountered when generating' 10 ... 'the EEG.epoch structure (used only in user scripts)']); return; - end; + end case { 'loaddata' 'savedata' 'chanconsist' 'icaconsist' 'epochconsist' }, res = ''; otherwise, error('eeg_checkset: unknown option'); - end; - end; - end; + end + end + end res = []; @@ -661,31 +669,31 @@ if size(EEG.setname,1) > 1 disp('eeg_checkset warning: invalid dataset name, removed'); EEG.setname = ''; - end; - end; + end + end else EEG.setname = ''; - end; + end % checking history and convert if necessary % ----------------------------------------- - if isfield(EEG, 'history') & size(EEG.history,1) > 1 + if isfield(EEG, 'history') && size(EEG.history,1) > 1 allcoms = cellstr(EEG.history); EEG.history = deblank(allcoms{1}); for index = 2:length(allcoms) EEG.history = [ EEG.history 10 deblank(allcoms{index}) ]; - end; - end; + end + end % read data if necessary % ---------------------- - if ischar(EEG.data) & nargin > 1 + if ischar(EEG.data) && nargin > 1 if strcmpi(varargin{1}, 'loaddata') EEG.data = eeg_getdatact(EEG); - end; - end; + end + end % save data if necessary % ---------------------- @@ -697,12 +705,12 @@ if isfield(EEG, 'datfile') if ~isempty(EEG.datfile) datfile = 1; - end; - end; + end + end % save data % --------- - if strcmpi(varargin{1}, 'savedata') & option_storedisk + if strcmpi(varargin{1}, 'savedata') && option_storedisk error('eeg_checkset: cannot call savedata any more'); % the code below is deprecated @@ -713,23 +721,24 @@ tmpdata = reshape(EEG.data, EEG.nbchan, EEG.pnts*EEG.trials); floatwrite( tmpdata', fullfile(EEG.filepath, EEG.datfile), 'ieee-le'); EEG.data = EEG.datfile; - end; + end EEG.icaact = []; % saving dataset % -------------- filename = fullfile(EEG(1).filepath, EEG(1).filename); - if ~ischar(EEG.data) & option_single, EEG.data = single(EEG.data); end; + if ~ischar(EEG.data) && option_single, EEG.data = single(EEG.data); end v = version; if str2num(v(1)) >= 7, save( filename, '-v6', '-mat', 'EEG'); % Matlab 7 else save( filename, '-mat', 'EEG'); - end; - if ~ischar(EEG.data), EEG.data = 'in set file'; end; + end + if ~ischar(EEG.data), EEG.data = 'in set file'; end - res = sprintf('%s = eeg_checkset( %s, ''savedata'');', inputname(1), inputname(1)); - end; - end; - end; + % res = sprintf('%s = eeg_checkset( %s, ''savedata'');', inputname(1), inputname(1)); + res = ['EEG = eeg_checkset( EEG, ''savedata'');']; + end + end + end % numerical format % ---------------- @@ -738,22 +747,22 @@ EEG.icawinv = double(EEG.icawinv); % required for dipole fitting, otherwise it crashes EEG.icaweights = double(EEG.icaweights); EEG.icasphere = double(EEG.icasphere); - if ~isempty(findstr(v, 'R11')) | ~isempty(findstr(v, 'R12')) | ~isempty(findstr(v, 'R13')) + if ~isempty(findstr(v, 'R11')) || ~isempty(findstr(v, 'R12')) || ~isempty(findstr(v, 'R13')) EEG.data = double(EEG.data); EEG.icaact = double(EEG.icaact); else try, - if isa(EEG.data, 'double') & option_single + if isa(EEG.data, 'double') && option_single EEG.data = single(EEG.data); EEG.icaact = single(EEG.icaact); - end; + end catch, disp('WARNING: EEGLAB ran out of memory while converting dataset to single precision.'); disp(' Save dataset (preferably saving data to a separate file; see File > Memory options).'); disp(' Then reload it.'); - end; - end; - end; + end + end + end % verify the type of the variables % -------------------------------- @@ -764,32 +773,29 @@ ') does not match the number of channels (' int2str(EEG.nbchan) '): corrected' ]); res = com; EEG.nbchan = size(EEG.data,1); - end; + end - if (ndims(EEG.data)) < 3 & (EEG.pnts > 1) + if (ndims(EEG.data)) < 3 && (EEG.pnts > 1) if mod(size(EEG.data,2), EEG.pnts) ~= 0 - if popask( [ 'eeg_checkset error: the number of frames does not divide the number of columns in the data.' 10 ... - 'Should EEGLAB attempt to abort operation ?' 10 '(press Cancel to fix the problem from the command line)']) - error('eeg_checkset error: user abort'); - %res = com; - %EEG.pnts = size(EEG.data,2); - %EEG = eeg_checkset(EEG); - %return; + fprintf(2, 'eeg_checkset error: binary data file likely truncated, importing anyway...\n'); + if EEG.trials > 1 + EEG.trials = floor(size(EEG.data,2)/EEG.pnts); + EEG.data(:,EEG.trials*EEG.pnts+1:end) = []; + res = com; else + EEG.pnts = size(EEG.data,2); res = com; - return; - %error( 'eeg_checkset error: number of points does not divide the number of columns in data'); - end; + end else if EEG.trials > 1 disp( 'eeg_checkset note: data array made 3-D'); res = com; - end; + end if size(EEG.data,2) ~= EEG.pnts EEG.data = reshape(EEG.data, EEG.nbchan, EEG.pnts, size(EEG.data,2)/EEG.pnts); - end; - end; - end; + end + end + end % size of data ----------- if size(EEG.data,3) ~= EEG.trials @@ -797,31 +803,41 @@ ') does not match the number of epochs (' int2str(EEG.trials) '), corrected' ]); res = com; EEG.trials = size(EEG.data,3); - end; + end if size(EEG.data,2) ~= EEG.pnts disp( [ 'eeg_checkset warning: number of columns in data (' int2str(size(EEG.data,2)) ... ') does not match the number of points (' int2str(EEG.pnts) '): corrected' ]); res = com; EEG.pnts = size(EEG.data,2); - end; - end; + end + end + % xmin must be 0 for continuous data or + % pop_select does not behave correctly when + % removing data points + % -------------------- + if EEG.trials == 1 && EEG.xmin ~= 0 + EEG.xmin = 0; + fprintf( 'eeg_checkset note: xmin set to 0 for continuous data\n'); + res = com; + end + % parameters consistency % ------------------------- if round(EEG.srate*(EEG.xmax-EEG.xmin)+1) ~= EEG.pnts fprintf( 'eeg_checkset note: upper time limit (xmax) adjusted so (xmax-xmin)*srate+1 = number of frames\n'); if EEG.srate == 0 EEG.srate = 1; - end; + end EEG.xmax = (EEG.pnts-1)/EEG.srate+EEG.xmin; res = com; - end; + end % deal with event arrays % ---------------------- - if ~isfield(EEG, 'event'), EEG.event = []; res = com; end; + if ~isfield(EEG, 'event'), EEG.event = []; res = com; end if ~isempty(EEG.event) - if EEG.trials > 1 & ~isfield(EEG.event, 'epoch') + if EEG.trials > 1 && ~isfield(EEG.event, 'epoch') if popask( [ 'eeg_checkset error: the event info structure does not contain an ''epoch'' field.' ... 'Should EEGLAB attempt to abort operation ?' 10 '(press Cancel to fix the problem from the commandline)']) error('eeg_checkset error(): user abort'); @@ -833,15 +849,19 @@ res = com; return; %error('eeg_checkset error: no epoch field in event structure'); - end; - end; + end + end else EEG.event = []; - end; + end + if isfield(EEG, 'urevent') && ~isempty(EEG.urevent) && ~isfield(EEG.event, 'urevent') && ~isempty(EEG.event) + warning('Inconsistency between urevent (backup) and event structures, removing urevent structure'); + EEG.urevent = []; + end if isempty(EEG.event) EEG.eventdescription = {}; - end; - if ~isfield(EEG, 'eventdescription') | ~iscell(EEG.eventdescription) + end + if ~isfield(EEG, 'eventdescription') || ~iscell(EEG.eventdescription) EEG.eventdescription = cell(1, length(fieldnames(EEG.event))); res = com; else @@ -850,42 +870,42 @@ EEG.eventdescription = EEG.eventdescription(1:length( fieldnames(EEG.event))); elseif length(EEG.eventdescription) < length( fieldnames(EEG.event)) EEG.eventdescription(end+1:length( fieldnames(EEG.event))) = {''}; - end; - end; - end; + end + end + end % create urevent if continuous data % --------------------------------- - %if ~isempty(EEG.event) & ~isfield(EEG, 'urevent') + %if ~isempty(EEG.event) && ~isfield(EEG, 'urevent') % EEG.urevent = EEG.event; % disp('eeg_checkset note: creating the original event table (EEG.urevent)'); % for index = 1:length(EEG.event) % EEG.event(index).urevent = index; - % end; - %end; - if isfield(EEG, 'urevent') & isfield(EEG.urevent, 'urevent') + % end + %end + if isfield(EEG, 'urevent') && isfield(EEG.urevent, 'urevent') EEG.urevent = rmfield(EEG.urevent, 'urevent'); - end; + end % deal with epoch arrays % ---------------------- - if ~isfield(EEG, 'epoch'), EEG.epoch = []; res = com; end; + if ~isfield(EEG, 'epoch'), EEG.epoch = []; res = com; end % check if only one epoch % ----------------------- if EEG.trials == 1 if isfield(EEG.event, 'epoch') EEG.event = rmfield(EEG.event, 'epoch'); res = com; - end; + end if ~isempty(EEG.epoch) EEG.epoch = []; res = com; - end; - end; + end + end - if ~isfield(EEG, 'epochdescription'), EEG.epochdescription = {}; res = com; end; + if ~isfield(EEG, 'epochdescription'), EEG.epochdescription = {}; res = com; end if ~isempty(EEG.epoch) if isstruct(EEG.epoch), l = length( EEG.epoch); else l = size( EEG.epoch, 2); - end; + end if l ~= EEG.trials if popask( [ 'eeg_checkset error: the number of epoch indices in the epoch array/struct (' ... int2str(l) ') is different from the number of epochs in the data (' int2str(EEG.trials) ').' 10 ... @@ -899,11 +919,11 @@ res = com; return; %error('eeg_checkset error: epoch structure size invalid'); - end; - end; + end + end else EEG.epoch = []; - end; + end % check ica % --------- @@ -912,14 +932,12 @@ EEG.icachansind = []; res = com; else EEG.icachansind = [1:EEG.nbchan]; res = com; - end; + end elseif isempty(EEG.icachansind) - if isempty(EEG.icaweights) - EEG.icachansind = []; res = com; - else + if ~isempty(EEG.icaweights) EEG.icachansind = [1:EEG.nbchan]; res = com; - end; - end; + end + end if ~isempty(EEG.icasphere) if ~isempty(EEG.icaweights) if size(EEG.icaweights,2) ~= size(EEG.icasphere,1) @@ -936,8 +954,8 @@ res = com; return; %error('eeg_checkset error: invalid weight and sphere array sizes'); - end; - end; + end + end if isnumeric(EEG.data) if length(EEG.icachansind) ~= size(EEG.icasphere,2) if popask( [ 'eeg_checkset error: number of elements in ''icachansind'' (' int2str(length(EEG.icachansind)) ')' 10 ... @@ -953,9 +971,9 @@ res = com; return; %error('eeg_checkset error: invalid weight and sphere array sizes'); - end; - end; - if isempty(EEG.icaact) | (size(EEG.icaact,1) ~= size(EEG.icaweights,1)) | (size(EEG.icaact,2) ~= size(EEG.data,2)) + end + end + if isempty(EEG.icaact) || (size(EEG.icaact,1) ~= size(EEG.icaweights,1)) || (size(EEG.icaact,2) ~= size(EEG.data,2)) EEG.icaweights = double(EEG.icaweights); EEG.icawinv = double(EEG.icawinv); @@ -970,9 +988,9 @@ EEG.icaweights = EEG.icaweights .* scaling; EEG.icawinv = pinv(EEG.icaweights * EEG.icasphere); - end; - end; - end; + end + end + end if ~isempty(EEG.data) && option_computeica fprintf('eeg_checkset: recomputing the ICA activation matrix ...\n'); @@ -986,59 +1004,71 @@ EEG.icaact(:,tmpindices) = (EEG.icaweights*EEG.icasphere)*tmpdata(:,tmpindices); else EEG.icaact = (EEG.icaweights*EEG.icasphere)*EEG.data(EEG.icachansind,:); % automatically does single or double - end; + end EEG.icaact = reshape( EEG.icaact, size(EEG.icaact,1), EEG.pnts, EEG.trials); - end; - end; - end; + end + end + end if isempty(EEG.icawinv) EEG.icawinv = pinv(EEG.icaweights*EEG.icasphere); % a priori same result as inv res = com; - end; + end else disp( [ 'eeg_checkset warning: weights matrix cannot be empty if sphere matrix is not, correcting ...' ]); res = com; EEG.icasphere = []; - end; + end if option_computeica - if ~isempty(EEG.icaact) & ndims(EEG.icaact) < 3 & (EEG.trials > 1) + if ~isempty(EEG.icaact) && ndims(EEG.icaact) < 3 && (EEG.trials > 1) disp( [ 'eeg_checkset note: independent component made 3-D' ]); res = com; EEG.icaact = reshape(EEG.icaact, size(EEG.icaact,1), EEG.pnts, EEG.trials); - end; + end else if ~isempty(EEG.icaact) fprintf('eeg_checkset: removing ICA activation matrix (as per edit options) ...\n'); - end; + end EEG.icaact = []; - end; + end else - if ~isempty( EEG.icaweights ), EEG.icaweights = []; res = com; end; - if ~isempty( EEG.icawinv ), EEG.icawinv = []; res = com; end; - if ~isempty( EEG.icaact ), EEG.icaact = []; res = com; end; - end; + if ~isfield(EEG, 'icaweights') || ~isempty( EEG.icaweights ), EEG.icaweights = []; res = com; end + if ~isfield(EEG, 'icawinv') || ~isempty( EEG.icawinv ), EEG.icawinv = []; res = com; end + if ~isfield(EEG, 'icaact') || ~isempty( EEG.icaact ), EEG.icaact = []; res = com; end + end if isempty(EEG.icaact) EEG.icaact = []; - end; + end % ------------- % check chanlocs % ------------- if ~isfield(EEG, 'chaninfo') EEG.chaninfo = []; - end; + end if ~isempty( EEG.chanlocs ) % reference (use EEG structure) % --------- - if ~isfield(EEG, 'ref'), EEG.ref = ''; end; - if strcmpi(EEG.ref, 'averef') - ref = 'average'; - else ref = ''; - end; + if ~isfield(EEG, 'ref') + EEG.ref = ''; + end + if isequal(EEG.ref, 'averef') + EEG.ref = 'average'; + res = com; + end + if isequal(EEG.ref, 'average') + ref = 'average'; + else ref = ''; + end if ~isfield( EEG.chanlocs, 'ref') EEG.chanlocs(1).ref = ref; - end; + end + if isfield(EEG.chanlocs, 'ref') && ~isempty(EEG.chanlocs(1).ref) + if ~isequal(EEG.chanlocs(1).ref, EEG.ref) + EEG.ref = EEG.chanlocs(1).ref; + res = com; + end + end charrefs = cellfun('isclass',{EEG.chanlocs.ref},'char'); if any(charrefs) ref = ''; end for tmpind = find(~charrefs) @@ -1053,62 +1083,22 @@ res = com; try, EEG.chanlocs = readlocs( EEG.chanlocs ); disp( [ 'eeg_checkset: channel file read' ]); - catch, EEG.chanlocs = []; end; - end; + catch, EEG.chanlocs = []; end + end else if ~isfield(EEG.chanlocs,'labels') disp('eeg_checkset warning: no field label in channel location structure, removing it'); EEG.chanlocs = []; res = com; - end; - end; + end + end if isstruct( EEG.chanlocs) if length( EEG.chanlocs) ~= EEG.nbchan && length( EEG.chanlocs) ~= EEG.nbchan+1 && ~isempty(EEG.data) disp( [ 'eeg_checkset warning: number of channels different in data and channel file/struct: channel file/struct removed' ]); EEG.chanlocs = []; res = com; - end; - end; - - % force Nosedir to +X (done here because of DIPFIT) - % ------------------- - if isfield(EEG.chaninfo, 'nosedir') - if strcmpi(EEG.chaninfo.nosedir, '+x') - rotate = 0; - elseif all(isfield(EEG.chanlocs,{'X','Y','theta','sph_theta'})) - disp('EEG checkset note for expert users: Noze direction now set to default +X in EEG.chanlocs and EEG.dipfit.'); - if strcmpi(EEG.chaninfo.nosedir, '+y') - rotate = 270; - elseif strcmpi(EEG.chaninfo.nosedir, '-x') - rotate = 180; - else rotate = 90; - end; - for index = 1:length(EEG.chanlocs) - if ~isempty(EEG.chanlocs(index).theta) - rotategrad = rotate/180*pi; - coord = (EEG.chanlocs(index).Y + EEG.chanlocs(index).X*sqrt(-1))*exp(sqrt(-1)*-rotategrad); - EEG.chanlocs(index).Y = real(coord); - EEG.chanlocs(index).X = imag(coord); - - EEG.chanlocs(index).theta = EEG.chanlocs(index).theta -rotate; - EEG.chanlocs(index).sph_theta = EEG.chanlocs(index).sph_theta+rotate; - if EEG.chanlocs(index).theta <-180, EEG.chanlocs(index).theta =EEG.chanlocs(index).theta +360; end; - if EEG.chanlocs(index).sph_theta>180 , EEG.chanlocs(index).sph_theta=EEG.chanlocs(index).sph_theta-360; end; - end; - end; - - if isfield(EEG, 'dipfit') - if isfield(EEG.dipfit, 'coord_transform') - if isempty(EEG.dipfit.coord_transform) - EEG.dipfit.coord_transform = [0 0 0 0 0 0 1 1 1]; - end; - EEG.dipfit.coord_transform(6) = EEG.dipfit.coord_transform(6)+rotategrad; - end; - end; - - end; - EEG.chaninfo.nosedir = '+X'; - end; + end + end % general checking of channels % ---------------------------- @@ -1118,39 +1108,44 @@ EEG.chaninfo = []; disp('Warning: the size of the channel location structure does not match with'); disp(' number of channels. Channel information have been removed.'); - end; - end; - EEG.chaninfo.icachansind = EEG.icachansind; % just a copy for programming convinience + end + end + EEG.chaninfo.icachansind = EEG.icachansind; % just a copy for programming convenience %if ~isfield(EEG, 'urchanlocs') % EEG.urchanlocs = EEG.chanlocs; % for index = 1:length(EEG.chanlocs) % EEG.chanlocs(index).urchan = index; - % end; + % end % disp('eeg_checkset note: creating backup chanlocs structure (urchanlocs)'); - %end; + %end + + % Field 'datachan in 'urchanlocs' is removed, if exist + if isfield(EEG, 'urchanlocs') && ~isempty(EEG.urchanlocs) && isfield(EEG.urchanlocs, 'datachan') + EEG.urchanlocs = rmfield(EEG.urchanlocs, 'datachan'); + end % check reference % --------------- if ~isfield(EEG, 'ref') EEG.ref = 'common'; - end; - if ischar(EEG.ref) & strcmpi(EEG.ref, 'common') + end + if ischar(EEG.ref) && strcmpi(EEG.ref, 'common') if length(EEG.chanlocs) > EEG.nbchan disp('Extra common reference electrode location detected'); EEG.ref = EEG.nbchan+1; - end; - end; + end + end % DIPFIT structure % ---------------- - if ~isfield(EEG,'dipfit') || isempty(EEG.dipfit) + if ~isfield(EEG,'dipfit') EEG.dipfit = []; res = com; else try % check if dipfitdefs is present dipfitdefs; - if isfield(EEG.dipfit, 'vol') & ~isfield(EEG.dipfit, 'hdmfile') + if isfield(EEG.dipfit, 'vol') && ~isfield(EEG.dipfit, 'hdmfile') if exist('pop_dipfit_settings') disp('Old DIPFIT structure detected: converting to DIPFIT 2 format'); EEG.dipfit.hdmfile = template_models(1).hdmfile; @@ -1160,30 +1155,30 @@ EEG.dipfit.coord_transform = []; EEG.saved = 'no'; res = com; - end; - end; + end + end if isfield(EEG.dipfit, 'hdmfile') if length(EEG.dipfit.hdmfile) > 8 - if strcmpi(EEG.dipfit.hdmfile(end-8), template_models(1).hdmfile(end-8)), EEG.dipfit.hdmfile = template_models(1).hdmfile; end; - if strcmpi(EEG.dipfit.hdmfile(end-8), template_models(2).hdmfile(end-8)), EEG.dipfit.hdmfile = template_models(2).hdmfile; end; - end; + if strcmpi(EEG.dipfit.hdmfile(end-8), template_models(1).hdmfile(end-8)), EEG.dipfit.hdmfile = template_models(1).hdmfile; end + if strcmpi(EEG.dipfit.hdmfile(end-8), template_models(2).hdmfile(end-8)), EEG.dipfit.hdmfile = template_models(2).hdmfile; end + end if length(EEG.dipfit.mrifile) > 8 - if strcmpi(EEG.dipfit.mrifile(end-8), template_models(1).mrifile(end-8)), EEG.dipfit.mrifile = template_models(1).mrifile; end; - if strcmpi(EEG.dipfit.mrifile(end-8), template_models(2).mrifile(end-8)), EEG.dipfit.mrifile = template_models(2).mrifile; end; - end; + if strcmpi(EEG.dipfit.mrifile(end-8), template_models(1).mrifile(end-8)), EEG.dipfit.mrifile = template_models(1).mrifile; end + if strcmpi(EEG.dipfit.mrifile(end-8), template_models(2).mrifile(end-8)), EEG.dipfit.mrifile = template_models(2).mrifile; end + end if length(EEG.dipfit.chanfile) > 8 - if strcmpi(EEG.dipfit.chanfile(end-8), template_models(1).chanfile(end-8)), EEG.dipfit.chanfile = template_models(1).chanfile; end; - if strcmpi(EEG.dipfit.chanfile(end-8), template_models(2).chanfile(end-8)), EEG.dipfit.chanfile = template_models(2).chanfile; end; - end; - end; + if strcmpi(EEG.dipfit.chanfile(end-8), template_models(1).chanfile(end-8)), EEG.dipfit.chanfile = template_models(1).chanfile; end + if strcmpi(EEG.dipfit.chanfile(end-8), template_models(2).chanfile(end-8)), EEG.dipfit.chanfile = template_models(2).chanfile; end + end + end if isfield(EEG.dipfit, 'coord_transform') if isempty(EEG.dipfit.coord_transform) EEG.dipfit.coord_transform = [0 0 0 0 0 0 1 1 1]; - end; + end elseif ~isempty(EEG.dipfit) EEG.dipfit.coord_transform = [0 0 0 0 0 0 1 1 1]; - end; + end catch e = lasterror; if ~strcmp(e.identifier,'MATLAB:UndefinedFunction') @@ -1191,7 +1186,7 @@ rethrow(e); end end - end; + end % check events (fast) % ------------ @@ -1201,43 +1196,45 @@ disp('Warning: converting all event types to strings'); for ind = 1:length(EEG.event) EEG.event(ind).type = num2str(EEG.event(ind).type); - end; + end EEG = eeg_checkset(EEG, 'eventconsistency'); - end; - end; + end + end % EEG.times (only for epoched datasets) % --------- if ~isfield(EEG, 'times') || isempty(EEG.times) || length(EEG.times) ~= EEG.pnts EEG.times = linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts); - end; + end - if ~isfield(EEG, 'history') EEG.history = ''; res = com; end; - if ~isfield(EEG, 'splinefile') EEG.splinefile = ''; res = com; end; - if ~isfield(EEG, 'icasplinefile') EEG.icasplinefile = ''; res = com; end; - if ~isfield(EEG, 'saved') EEG.saved = 'no'; res = com; end; - if ~isfield(EEG, 'subject') EEG.subject = ''; res = com; end; - if ~isfield(EEG, 'condition') EEG.condition = ''; res = com; end; - if ~isfield(EEG, 'group') EEG.group = ''; res = com; end; - if ~isfield(EEG, 'session') EEG.session = []; res = com; end; - if ~isfield(EEG, 'urchanlocs') EEG.urchanlocs = []; res = com; end; - if ~isfield(EEG, 'specdata') EEG.specdata = []; res = com; end; - if ~isfield(EEG, 'specicaact') EEG.specicaact = []; res = com; end; - if ~isfield(EEG, 'comments') EEG.comments = ''; res = com; end; - if ~isfield(EEG, 'etc' ) EEG.etc = []; res = com; end; - if ~isfield(EEG, 'urevent' ) EEG.urevent = []; res = com; end; - if ~isfield(EEG, 'ref') | isempty(EEG.ref) EEG.ref = 'common'; res = com; end; + if ~isfield(EEG, 'history') EEG.history = ''; res = com; end + if ~isfield(EEG, 'splinefile') EEG.splinefile = ''; res = com; end + if ~isfield(EEG, 'icasplinefile') EEG.icasplinefile = ''; res = com; end + if ~isfield(EEG, 'saved') EEG.saved = 'no'; res = com; end + if ~isfield(EEG, 'subject') EEG.subject = ''; res = com; end + if ~isfield(EEG, 'condition') EEG.condition = ''; res = com; end + if ~isfield(EEG, 'group') EEG.group = ''; res = com; end + if ~isfield(EEG, 'run') EEG.run = []; res = com; end + if ~isfield(EEG, 'session') EEG.session = []; res = com; end + if ~isfield(EEG, 'urchanlocs') EEG.urchanlocs = []; res = com; end + if ~isfield(EEG, 'specdata') EEG.specdata = []; res = com; end + if ~isfield(EEG, 'specicaact') EEG.specicaact = []; res = com; end + if ~isfield(EEG, 'comments') EEG.comments = ''; res = com; end + if ~isfield(EEG, 'etc' ) EEG.etc = []; res = com; end + if ~isfield(EEG, 'urevent' ) EEG.urevent = []; res = com; end + if ~isfield(EEG, 'roi' ) EEG.roi = []; res = com; end + if ~isfield(EEG, 'ref') || isempty(EEG.ref) EEG.ref = 'common'; res = com; end % create fields if absent % ----------------------- - if ~isfield(EEG, 'reject') EEG.reject.rejjp = []; res = com; end; + if ~isfield(EEG, 'reject') EEG.reject.rejjp = []; res = com; end listf = { 'rejjp' 'rejkurt' 'rejmanual' 'rejthresh' 'rejconst', 'rejfreq' ... 'icarejjp' 'icarejkurt' 'icarejmanual' 'icarejthresh' 'icarejconst', 'icarejfreq'}; for index = 1:length(listf) name = listf{index}; elecfield = [name 'E']; - if ~isfield(EEG.reject, elecfield), EEG.reject.(elecfield) = []; res = com; end; + if ~isfield(EEG.reject, elecfield), EEG.reject.(elecfield) = []; res = com; end if ~isfield(EEG.reject, name) EEG.reject.(name) = []; res = com; @@ -1245,51 +1242,60 @@ % check if electrode array is empty with rejection array is not nbchan = fastif(strcmp(name, 'ica'), size(EEG.icaweights,1), EEG.nbchan); EEG.reject = setfield(EEG.reject, elecfield, zeros(nbchan, length(getfield(EEG.reject, name)))); res = com; - end; - end; - if ~isfield(EEG.reject, 'rejglobal') EEG.reject.rejglobal = []; res = com; end; - if ~isfield(EEG.reject, 'rejglobalE') EEG.reject.rejglobalE = []; res = com; end; + end + end + if ~isfield(EEG.reject, 'rejglobal') EEG.reject.rejglobal = []; res = com; end + if ~isfield(EEG.reject, 'rejglobalE') EEG.reject.rejglobalE = []; res = com; end + + % track version of EEGLAB + % ----------------------- + tmpvers = eeg_getversion; + if ~isfield(EEG.etc, 'eeglabvers') || ~isequal(EEG.etc.eeglabvers, tmpvers) + EEG.etc.eeglabvers = tmpvers; + EEG = eeg_hist( EEG, ['EEG.etc.eeglabvers = ''' tmpvers '''; % this tracks which version of EEGLAB is being used, you may ignore it'] ); + res = com; + end % default colors for rejection % ---------------------------- - if ~isfield(EEG.reject, 'rejmanualcol') EEG.reject.rejmanualcol = [1.0000 1 0.783]; res = com; end; - if ~isfield(EEG.reject, 'rejthreshcol') EEG.reject.rejthreshcol = [0.8487 1.0000 0.5008]; res = com; end; - if ~isfield(EEG.reject, 'rejconstcol') EEG.reject.rejconstcol = [0.6940 1.0000 0.7008]; res = com; end; - if ~isfield(EEG.reject, 'rejjpcol') EEG.reject.rejjpcol = [1.0000 0.6991 0.7537]; res = com; end; - if ~isfield(EEG.reject, 'rejkurtcol') EEG.reject.rejkurtcol = [0.6880 0.7042 1.0000]; res = com; end; - if ~isfield(EEG.reject, 'rejfreqcol') EEG.reject.rejfreqcol = [0.9596 0.7193 1.0000]; res = com; end; - if ~isfield(EEG.reject, 'disprej') EEG.reject.disprej = { }; end; + if ~isfield(EEG.reject, 'rejmanualcol') EEG.reject.rejmanualcol = [1.0000 1 0.783]; res = com; end + if ~isfield(EEG.reject, 'rejthreshcol') EEG.reject.rejthreshcol = [0.8487 1.0000 0.5008]; res = com; end + if ~isfield(EEG.reject, 'rejconstcol') EEG.reject.rejconstcol = [0.6940 1.0000 0.7008]; res = com; end + if ~isfield(EEG.reject, 'rejjpcol') EEG.reject.rejjpcol = [1.0000 0.6991 0.7537]; res = com; end + if ~isfield(EEG.reject, 'rejkurtcol') EEG.reject.rejkurtcol = [0.6880 0.7042 1.0000]; res = com; end + if ~isfield(EEG.reject, 'rejfreqcol') EEG.reject.rejfreqcol = [0.9596 0.7193 1.0000]; res = com; end + if ~isfield(EEG.reject, 'disprej') EEG.reject.disprej = { }; end - if ~isfield(EEG, 'stats') EEG.stats.jp = []; res = com; end; - if ~isfield(EEG.stats, 'jp') EEG.stats.jp = []; res = com; end; - if ~isfield(EEG.stats, 'jpE') EEG.stats.jpE = []; res = com; end; - if ~isfield(EEG.stats, 'icajp') EEG.stats.icajp = []; res = com; end; - if ~isfield(EEG.stats, 'icajpE') EEG.stats.icajpE = []; res = com; end; - if ~isfield(EEG.stats, 'kurt') EEG.stats.kurt = []; res = com; end; - if ~isfield(EEG.stats, 'kurtE') EEG.stats.kurtE = []; res = com; end; - if ~isfield(EEG.stats, 'icakurt') EEG.stats.icakurt = []; res = com; end; - if ~isfield(EEG.stats, 'icakurtE') EEG.stats.icakurtE = []; res = com; end; + if ~isfield(EEG, 'stats') EEG.stats.jp = []; res = com; end + if ~isfield(EEG.stats, 'jp') EEG.stats.jp = []; res = com; end + if ~isfield(EEG.stats, 'jpE') EEG.stats.jpE = []; res = com; end + if ~isfield(EEG.stats, 'icajp') EEG.stats.icajp = []; res = com; end + if ~isfield(EEG.stats, 'icajpE') EEG.stats.icajpE = []; res = com; end + if ~isfield(EEG.stats, 'kurt') EEG.stats.kurt = []; res = com; end + if ~isfield(EEG.stats, 'kurtE') EEG.stats.kurtE = []; res = com; end + if ~isfield(EEG.stats, 'icakurt') EEG.stats.icakurt = []; res = com; end + if ~isfield(EEG.stats, 'icakurtE') EEG.stats.icakurtE = []; res = com; end % component rejection % ------------------- - if ~isfield(EEG.stats, 'compenta') EEG.stats.compenta = []; res = com; end; - if ~isfield(EEG.stats, 'compentr') EEG.stats.compentr = []; res = com; end; - if ~isfield(EEG.stats, 'compkurta') EEG.stats.compkurta = []; res = com; end; - if ~isfield(EEG.stats, 'compkurtr') EEG.stats.compkurtr = []; res = com; end; - if ~isfield(EEG.stats, 'compkurtdist') EEG.stats.compkurtdist = []; res = com; end; - if ~isfield(EEG.reject, 'threshold') EEG.reject.threshold = [0.8 0.8 0.8]; res = com; end; - if ~isfield(EEG.reject, 'threshentropy') EEG.reject.threshentropy = 600; res = com; end; - if ~isfield(EEG.reject, 'threshkurtact') EEG.reject.threshkurtact = 600; res = com; end; - if ~isfield(EEG.reject, 'threshkurtdist') EEG.reject.threshkurtdist = 600; res = com; end; - if ~isfield(EEG.reject, 'gcompreject') EEG.reject.gcompreject = []; res = com; end; + if ~isfield(EEG.stats, 'compenta') EEG.stats.compenta = []; res = com; end + if ~isfield(EEG.stats, 'compentr') EEG.stats.compentr = []; res = com; end + if ~isfield(EEG.stats, 'compkurta') EEG.stats.compkurta = []; res = com; end + if ~isfield(EEG.stats, 'compkurtr') EEG.stats.compkurtr = []; res = com; end + if ~isfield(EEG.stats, 'compkurtdist') EEG.stats.compkurtdist = []; res = com; end + if ~isfield(EEG.reject, 'threshold') EEG.reject.threshold = [0.8 0.8 0.8]; res = com; end + if ~isfield(EEG.reject, 'threshentropy') EEG.reject.threshentropy = 600; res = com; end + if ~isfield(EEG.reject, 'threshkurtact') EEG.reject.threshkurtact = 600; res = com; end + if ~isfield(EEG.reject, 'threshkurtdist') EEG.reject.threshkurtdist = 600; res = com; end + if ~isfield(EEG.reject, 'gcompreject') EEG.reject.gcompreject = []; res = com; end if length(EEG.reject.gcompreject) ~= size(EEG.icaweights,1) EEG.reject.gcompreject = zeros(1, size(EEG.icaweights,1)); - end; + end % remove old fields % ----------------- - if isfield(EEG, 'averef'), EEG = rmfield(EEG, 'averef'); end; - if isfield(EEG, 'rt' ), EEG = rmfield(EEG, 'rt'); end; + if isfield(EEG, 'averef'), EEG = rmfield(EEG, 'averef'); end + if isfield(EEG, 'rt' ), EEG = rmfield(EEG, 'rt'); end % store in new structure % ---------------------- @@ -1298,9 +1304,9 @@ ALLEEGNEW = EEG; else ALLEEGNEW(inddataset) = EEG; - end; - end; -end; + end + end +end % recorder fields % --------------- @@ -1354,18 +1360,17 @@ try ALLEEGNEW = orderfields(ALLEEGNEW, fieldorder); - EEG = ALLEEGNEW; catch disp('Couldn''t order data set fields properly.'); -end; +end if exist('ALLEEGNEW','var') - EEG = ALLEEGNEW; -end; + EEGFINAL = ALLEEGNEW; +end if ~isa(EEG, 'eegobj') && option_eegobject - EEG = eegobj(EEG); -end; + EEGFINAL = eegobj(EEG); +end return; @@ -1375,20 +1380,20 @@ switch lower(ButtonName), case 'cancel', num = 0; case 'yes', num = 1; -end; +end function res = mycellfun(com, vals, classtype); res = zeros(1, length(vals)); switch com case 'isempty', - for index = 1:length(vals), res(index) = isempty(vals{index}); end; + for index = 1:length(vals), res(index) = isempty(vals{index}); end case 'isclass' if strcmp(classtype, 'double') - for index = 1:length(vals), res(index) = isnumeric(vals{index}); end; + for index = 1:length(vals), res(index) = isnumeric(vals{index}); end else error('unknown cellfun command'); - end; + end otherwise error('unknown cellfun command'); -end; +end diff --git a/functions/adminfunc/eeg_eval.m b/functions/adminfunc/eeg_eval.m index 1ab1412ee..355bad23c 100644 --- a/functions/adminfunc/eeg_eval.m +++ b/functions/adminfunc/eeg_eval.m @@ -1,4 +1,4 @@ -% eeg_eval() - apply eeglab function to a collection of input datasets +% EEG_EVAL - apply eeglab function to a collection of input datasets % % Usage: % >> OUTEEG = eeg_eval(funcname, INEEG, 'key1', value1, 'key2', value2 ...); @@ -18,37 +18,48 @@ % % Author: Arnaud Delorme, SCCN, INC, UCSD, 2005 % -% see also: eeglab() +% see also: EEGLAB % Copyright (C) 2005 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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, com] = eeg_eval( funcname, EEG, varargin); +function [EEG, com] = eeg_eval( funcname, EEG, varargin) com = ''; if nargin < 2 help eeg_eval; return; - end; + end % check input parameters % ---------------------- g = finputcheck( varargin, { 'params' 'cell' {} {}; - 'warning' 'string' { 'on','off' } 'on' }, 'eeg_eval'); - if isstr(g), error(g); end; + 'warning' 'string' { 'on','off' } 'off' }, 'eeg_eval'); + if ischar(g), error(g); end % warning pop up % -------------- @@ -64,53 +75,91 @@ res = questdlg2( [ 'Data files on disk will be automatically overwritten.' 10 ... 'Are you sure you want to proceed with this operation?' ], ... 'Confirmation', 'Cancel', 'Proceed', 'Proceed'); - end; - switch lower(res), - case 'cancel', return; - case 'proceed',; - end; - end; + end + switch lower(res) + case 'cancel', return; + case 'proceed' + end + vPar = ver('parallel'); + if option_parallel && ~isempty(vPar) + res = questdlg2(strvcat( 'You have selected to use the parallel toolbox,', ... + 'to process multiple datasets. If you saturate the ', ... + 'memory, this could cause your computer to become.', ... + 'unresponsive or even crash.'), ... + 'Multiple dataset warning', 'Cancel', 'Proceed', 'Proceed'); + end + switch lower(res) + case 'cancel', return; + case 'proceed' + end + end % execute function % ---------------- v = version; if str2num(v(1)) == '5' % Matlab 5 command = [ 'TMPEEG = ' funcname '( TMPEEG, ' vararg2str(g.params) ');' ]; - else + elseif isstr(funcname) eval( [ 'func = @' funcname ';' ] ); - end; - - NEWEEG = []; - for i = 1:length(EEG) - fprintf('Processing group dataset %d of %d named: %s ****************\n', i, length(EEG), EEG(i).setname); - TMPEEG = eeg_retrieve(EEG, i); - if v(1) == '5', eval(command); % Matlab 5 - else TMPEEG = feval(func, TMPEEG, g.params{:}); % Matlab 6 and higher - end; - TMPEEG = eeg_checkset(TMPEEG); - TMPEEG.saved = 'no'; - if option_storedisk - TMPEEG = pop_saveset(TMPEEG, 'savemode', 'resave'); - TMPEEG = update_datafield(TMPEEG); - end; - NEWEEG = eeg_store(NEWEEG, TMPEEG, i); - if option_storedisk - NEWEEG(i).saved = 'yes'; % eeg_store by default set it to no - end; - end; + else + func = funcname; + end + +% notCompatibleFunc = { +% @clean_artifacts +% }; + + NEWEEG = EEG; + if option_parallel + disp('Using the parallel toolbox to process multiple datasets (change in File > Preferences)'); + myPool = gcp; + tmpoptions_store = option_storedisk; + parfor i = 1:length(EEG) + fprintf('Processing group dataset %d of %d named: %s ****************\n', i, length(EEG), EEG(i).setname); + TMPEEG = eeg_retrieve(EEG, i); + TMPEEG = feval(func, TMPEEG, g.params{:}); + TMPEEG = eeg_checkset(TMPEEG); + TMPEEG.saved = 'no'; + if tmpoptions_store + TMPEEG = pop_saveset(TMPEEG, 'savemode', 'resave'); + TMPEEG = update_datafield(TMPEEG); + NEWEEG(i) = TMPEEG; + NEWEEG(i).saved = 'yes'; % eeg_store by default set it to no + else + NEWEEG(i) = TMPEEG; + NEWEEG(i).saved = 'yes'; % eeg_store by default set it to no + end + end + else + for i = 1:length(EEG) + fprintf('Processing group dataset %d of %d named: %s ****************\n', i, length(EEG), EEG(i).setname); + TMPEEG = eeg_retrieve(EEG, i); + TMPEEG = feval(func, TMPEEG, g.params{:}); + TMPEEG = eeg_checkset(TMPEEG); + TMPEEG.saved = 'no'; + if option_storedisk + TMPEEG = pop_saveset(TMPEEG, 'savemode', 'resave'); + TMPEEG = update_datafield(TMPEEG); + end + NEWEEG = eeg_store(NEWEEG, TMPEEG, i); + if option_storedisk + NEWEEG(i).saved = 'yes'; % eeg_store by default set it to no + end + end + end EEG = NEWEEG; % history % ------- if nargout > 1 - com = sprintf('%s = %s( %s,%s);', funcname, inputname(2), funcname, inputname(2), vararg2str(g.params)); - end; + com = sprintf('%s = %s( %s,%s);', inputname(2), char(funcname), inputname(2), vararg2str(g.params)); + end -function EEG = update_datafield(EEG); - if ~isfield(EEG, 'datfile'), EEG.datfile = ''; end; +function EEG = update_datafield(EEG) + if ~isfield(EEG, 'datfile'), EEG.datfile = ''; end if ~isempty(EEG.datfile) EEG.data = EEG.datfile; else EEG.data = 'in set file'; - end; + end EEG.icaact = []; diff --git a/functions/adminfunc/eeg_getdatact.m b/functions/adminfunc/eeg_getdatact.m index 66c113d67..7151d4754 100644 --- a/functions/adminfunc/eeg_getdatact.m +++ b/functions/adminfunc/eeg_getdatact.m @@ -1,4 +1,4 @@ -% eeg_getdatact() - get EEG data from a specified dataset or +% EEG_GETDATACT - get EEG data from a specified dataset or % component activity % % Usage: @@ -29,35 +29,46 @@ % % Author: Arnaud Delorme, SCCN & CERCO, CNRS, 2008- % -% See also: eeg_checkset() +% See also: EEG_CHECKSET % Copyright (C) 15 Feb 2002 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [data boundaries] = eeg_getdatact( EEG, varargin); +function [data, boundaries] = eeg_getdatact( EEG, varargin) data = []; if nargin < 1 help eeg_getdatact; return; -end; +end % reading data from several datasets and concatening it % ----------------------------------------------------- -if iscell(EEG) || (~isstr(EEG) && length(EEG) > 1) +if iscell(EEG) || (~ischar(EEG) && length(EEG) > 1) % decode some arguments % --------------------- trials = cell(1,length(EEG)); @@ -69,9 +80,9 @@ elseif strcmpi(varargin{iArg}, 'rmcomps') rmcomps = varargin{iArg+1}; varargin(iArg:iArg+1) = []; - end; - end; - if isnumeric(rmcomps), rmtmp = rmcomps; rmcomps = cell(1,length(EEG)); rmcomps(:) = { rmtmp }; end; + end + end + if isnumeric(rmcomps), rmtmp = rmcomps; rmcomps = cell(1,length(EEG)); rmcomps(:) = { rmtmp }; end % concatenate datasets % -------------------- @@ -79,38 +90,39 @@ boundaries = []; for dat = 1:length(EEG) if iscell(EEG) - [tmpdata datboundaries] = eeg_getdatact(EEG{dat}, 'trialindices', trials{dat}, 'rmcomps', rmcomps{dat}, varargin{:} ); - else [tmpdata datboundaries] = eeg_getdatact(EEG(dat), 'trialindices', trials{dat}, 'rmcomps', rmcomps{dat}, varargin{:} ); - end; - if isempty(data), + [tmpdata, datboundaries] = eeg_getdatact(EEG{dat}, 'trialindices', trials{dat}, 'rmcomps', rmcomps{dat}, varargin{:} ); + else [tmpdata, datboundaries] = eeg_getdatact(EEG(dat), 'trialindices', trials{dat}, 'rmcomps', rmcomps{dat}, varargin{:} ); + end + if isempty(data) data = tmpdata; boundaries = datboundaries; else - if all([ EEG.trials ] == 1) % continuous data - if size(data,1) ~= size(tmpdata,1), error('Datasets to be concatenated do not have the same number of channels'); end; + if (isstruct(EEG) && all([EEG.trials] == 1)) || size(tmpdata,3) == 1 || size(data,2) ~= size(tmpdata,2) % continuous data (if same number of data points, consider 1 trial dataset) + if size(tmpdata,3) ~= 1 || size(data,3) ~= 1, error('Trying to concatenate continuous and epoched datasets'); end + if size(data,1) ~= size(tmpdata,1), error('Datasets to be concatenated do not have the same number of channels'); end % adding boundaries if ~isempty(datboundaries) boundaries = [boundaries datboundaries size(data,2)]; else boundaries = [boundaries size(data,2)]; - end; + end data(:,end+1:end+size(tmpdata,2)) = tmpdata; % concatenating trials else - if size(data,1) ~= size(tmpdata,1), error('Datasets to be concatenated do not have the same number of channels'); end; - if size(data,2) ~= size(tmpdata,2), error('Datasets to be concatenated do not have the same number of time points'); end; + if size(data,1) ~= size(tmpdata,1), error('Datasets to be concatenated do not have the same number of channels'); end + if size(data,2) ~= size(tmpdata,2), error('Datasets to be concatenated do not have the same number of time points'); end data(:,:,end+1:end+size(tmpdata,3)) = tmpdata; % concatenating trials - end; - end; - end; + end + end + end return; -end; +end % if string load dataset % ---------------------- -if isstr(EEG) +if ischar(EEG) EEG = pop_loadset('filename', EEG, 'loadmode', 'info'); -end; +end opt = finputcheck(varargin, { ... 'channel' 'integer' {} []; @@ -123,54 +135,54 @@ 'trialindices' {'integer','cell'} { {} {} } []; 'rmcomps' {'integer','cell'} { {} {} } [] }, 'eeg_getdatact'); -if isstr(opt), error(opt); end; +if ischar(opt), error(opt); end channelNotDefined = 0; if isempty(opt.channel), opt.channel = [1:EEG.nbchan]; channelNotDefined = 1; elseif isequal(opt.channel, [1:EEG.nbchan]) && ~isempty(opt.interp) channelNotDefined = 1; -end; -if isempty(opt.trialindices), opt.trialindices = [1:EEG.trials]; end; -if iscell( opt.trialindices), opt.trialindices = opt.trialindices{1}; end; -if iscell(opt.rmcomps ), opt.rmcomps = opt.rmcomps{1}; end; -if (~isempty(opt.rmcomps) | ~isempty(opt.component)) & isempty(EEG.icaweights) +end +if iscell( opt.trialindices), opt.trialindices = opt.trialindices{1}; end +if isempty(opt.trialindices), opt.trialindices = [1:EEG.trials]; end +if iscell(opt.rmcomps ), opt.rmcomps = opt.rmcomps{1}; end +if (~isempty(opt.rmcomps) || ~isempty(opt.component)) && isempty(EEG.icaweights) error('No ICA weight in dataset'); -end; +end if strcmpi(EEG.data, 'in set file') - EEG = pop_loadset('filename', EEG.filename, 'filepath', EEG.filepath); -end; + EEG = pop_loadset('filename', EEG.filename, 'filepath', EEG.filepath, 'verbose', 'off'); +end % get data boundaries if continuous data % -------------------------------------- boundaries = []; -if nargout > 1 && EEG.trials == 1 && ~isempty(EEG.event) && isfield(EEG.event, 'type') && isstr(EEG.event(1).type) +if nargout > 1 && EEG.trials == 1 && ~isempty(EEG.event) && isfield(EEG.event, 'type') && ischar(EEG.event(1).type) if ~isempty(opt.samples) disp('WARNING: eeg_getdatact.m, boundaries are not accurate when selecting data samples'); - end; + end tmpevent = EEG.event; tmpbound = strmatch('boundary', lower({ tmpevent.type })); if ~isempty(tmpbound) boundaries = [tmpevent(tmpbound).latency ]-0.5; - end; -end; + end +end % getting channel or component activation % --------------------------------------- filename = fullfile(EEG.filepath, [ EEG.filename(1:end-4) '.icaact' ] ); -if ~isempty(opt.component) & ~isempty(EEG.icaact) +if ~isempty(opt.component) && ~isempty(EEG.icaact) data = EEG.icaact(opt.component,:,:); -elseif ~isempty(opt.component) & exist(filename) +elseif ~isempty(opt.component) && exist(filename) % reading ICA file % ---------------- data = repmat(single(0), [ length(opt.component) EEG.pnts EEG.trials ]); fid = fopen( filename, 'r', 'ieee-le'); %little endian (see also pop_saveset) - if fid == -1, error( ['file ' filename ' could not be open' ]); end; + if fid == -1, error( ['file ' filename ' could not be open' ]); end for ind = 1:length(opt.component) fseek(fid, (opt.component(ind)-1)*EEG.pnts*EEG.trials*4, -1); data(ind,:) = fread(fid, [EEG.trials*EEG.pnts 1], 'float32')'; - end; + end fclose(fid); elseif ~isempty(opt.component) @@ -180,25 +192,30 @@ data = (EEG.icaweights(opt.component,:)*EEG.icasphere)*data(EEG.icachansind,:); else data = EEG.icaact(opt.component,:,:); - end; + end else if isnumeric(EEG.data) % channel data = EEG.data; - else % channel but no data loaded - + else % channel but no data loaded string + + [~,EEG.data,ext] = fileparts(EEG.data); % remove path if present + EEG.data = [ EEG.data ext]; filename = fullfile(EEG.filepath, EEG.data); fid = fopen( filename, 'r', 'ieee-le'); %little endian (see also pop_saveset) if fid == -1 - error( ['file ' filename ' not found. If you have renamed/moved' 10 ... - 'the .set file, you must also rename/move the associated data file.' ]); - else - if strcmpi(opt.verbose, 'on') - fprintf('Reading float file ''%s''...\n', filename); - end; - end; + filename = fullfile(EEG.data); + fid = fopen( filename, 'r', 'ieee-le'); %little endian (see also pop_saveset) + if fid == -1 + error( ['file ' filename ' not found. If you have renamed/moved' 10 ... + 'the .set file, you must also rename/move the associated data file.' ]); + end + end + if strcmpi(opt.verbose, 'on') + fprintf('Reading float file ''%s''...\n', filename); + end % old format = .fdt; new format = .dat (transposed) % ------------------------------------------------- @@ -206,8 +223,8 @@ if length(filename) > 3 if strcmpi(filename(end-2:end), 'dat') datformat = 1; - end; - end; + end + end EEG.datfile = EEG.data; % reading data file @@ -226,23 +243,23 @@ for ind = 1:length(opt.channel) fseek(fid, (opt.channel(ind)-1)*EEG.pnts*EEG.trials*4, -1); data(ind,:) = fread(fid, [EEG.trials*EEG.pnts 1], 'float32')'; - end; + end opt.channel = [1:size(data,1)]; - end; + end else data = fread(fid, [EEG.nbchan Inf], 'float32'); - end; + end fclose(fid); - end; + end - end; + end % subracting components from data % ------------------------------- if ~isempty(opt.rmcomps) if strcmpi(opt.verbose, 'on') fprintf('Removing %d artifactual components\n', length(opt.rmcomps)); - end; + end rmcomps = eeg_getdatact( EEG, 'component', opt.rmcomps); % loaded from file rmchan = []; rmchanica = []; @@ -251,8 +268,8 @@ if ~isempty(tmpicaind) rmchan = [ rmchan index ]; rmchanica = [ rmchanica tmpicaind ]; - end; - end; + end + end data(rmchan,:) = data(rmchan,:) - EEG.icawinv(rmchanica,opt.rmcomps)*rmcomps(:,:); %EEG = eeg_checkset(EEG, 'loaddata'); @@ -261,8 +278,8 @@ %if strcmpi(EEG.subject, 'julien') & strcmpi(EEG.condition, 'oddball') & strcmpi(EEG.group, 'after') % jjjjf - %end; - end; + %end + end if ~isempty(opt.interp) EEG.data = data; @@ -270,13 +287,13 @@ EEG.epoch = []; EEG = eeg_interp(EEG, opt.interp, 'spherical'); data = EEG.data; - if channelNotDefined, opt.channel = [1:EEG.nbchan]; end; - end; + if channelNotDefined, opt.channel = [1:EEG.nbchan]; end + end if ~isequal(opt.channel, [1:EEG.nbchan]) data = data(intersect(opt.channel,[1:EEG.nbchan]),:,:); - end; -end; + end +end % projecting components on data channels @@ -284,38 +301,38 @@ if ~isempty(opt.projchan) if iscell(opt.projchan) opt.projchan = std_chaninds(EEG, opt.projchan); - end; + end finalChanInds = []; for iChan = 1:length(opt.projchan) tmpInd = find(EEG.icachansind == opt.projchan(iChan)); if isempty(tmpInd) error(sprintf('Warning: can not backproject component on channel %d (not used for ICA)\n', opt.projchan(iChan))); - end; + end finalChanInds = [ finalChanInds tmpInd ]; - end; + end data = EEG.icawinv(finalChanInds, opt.component)*data(:,:); -end; +end if size(data,2)*size(data,3) ~= EEG.pnts*EEG.trials disp('WARNING: The file size on disk does not correspond to the dataset, file has been truncated'); -end; -try, - if EEG.trials == 1, EEG.pnts = size(data,2); end; +end +try + if EEG.trials == 1, EEG.pnts = size(data,2); end if strcmpi(opt.reshape, '3d') data = reshape(data, size(data,1), EEG.pnts, EEG.trials); else data = reshape(data, size(data,1), EEG.pnts*EEG.trials); - end; + end catch error('The file size on disk does not correspond to the dataset information.'); -end; +end % select trials % ------------- if length(opt.trialindices) ~= EEG.trials data = data(:,:,opt.trialindices); -end; +end if ~isempty(opt.samples) data = data(:,opt.samples,:); -end; +end diff --git a/functions/adminfunc/eeg_getversion.m b/functions/adminfunc/eeg_getversion.m index 6811e90e4..3e2c4270a 100644 --- a/functions/adminfunc/eeg_getversion.m +++ b/functions/adminfunc/eeg_getversion.m @@ -1,4 +1,5 @@ -% eeg_getversion() - obtain EEGLAB version number +% EEG_GETVERSION - obtain EEGLAB version number (version is embedded in +% the script, edit the function to see the version). % % Usage: % >> vers = eeg_getversion; @@ -13,37 +14,40 @@ % Copyright (C) 2010 Arnaud Delorme, SCCN/INC/UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software - -function [vers, versnum, releaseDate] = eeg_getversion; - -vers = ''; -filepath = fileparts(which('eeglab.m')); -filename = dir(fullfile(filepath, 'Contents.m')); - -releaseDate = filename.date; +% 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. -if isempty(filename), return; end; +function [vers, versnum, releaseDate] = eeg_getversion -fid = fopen(fullfile(filepath, filename.name), 'r'); -fgetl(fid); -versionline = fgetl(fid); -vers = versionline(11:end); -fclose(fid); +vers = 'dev'; +releaseDate = '17-Feb-23 14:55:42'; % unix date -> date +"%d-%b-%y %T" +% get numerical version number tmpvers = vers; -if isempty(str2num(tmpvers(end))), tmpvers(end) = []; end; +if isnan(str2double(tmpvers(end))), tmpvers(end) = []; end indsDot = find(tmpvers == '.' ); tmpvers(indsDot(2:end)) = []; -versnum = str2num(tmpvers); \ No newline at end of file +versnum = str2double(tmpvers); +if isnan(versnum), versnum = []; end diff --git a/functions/adminfunc/eeg_global.m b/functions/adminfunc/eeg_global.m index 6b32dd6be..b2010fde8 100644 --- a/functions/adminfunc/eeg_global.m +++ b/functions/adminfunc/eeg_global.m @@ -1,6 +1,6 @@ -% eeg_global() - declare global EEGLAB variables. These variables are -% used only as global by the main function eeglab(), -% the function pop_rejmenu() and the history eegh() function. +% EEG_GLOBAL - declare global EEGLAB variables. These variables are +% used only as global by the main function EEGLAB, +% the function POP_REJMENU and the history EEGH function. % % Global variables: % EEG - structure containing the current dataset @@ -12,39 +12,65 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % -% See also: eeglab() +% See also: EEGLAB % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % global variables % ---------------- -global EEG; % current dataset -global ALLEEG; % all datasets -global CURRENTSET; % current set index +globalvars = who('global'); +if ~isempty(strmatch('ALLCOM', globalvars, 'exact')) || exist('ALLCOM') ~= 1 + tmpEEG = whos('EEG'); + % avoid overwritting variable in the current space + % in case it is not global + if ~isempty(tmpEEG) && ~tmpEEG.global + TMPEEG = EEG; + clear EEG; + global EEG; + EEG = TMPEEG; + else + global EEG; % current dataset + end + global ALLEEG; % all datasets + global CURRENTSET; % current set index -%global W_MAIN; % main window -%global H_MAIN; % main window -%global EEGMENU; % main menu -global ALLCOM; % all commands (history) -global LASTCOM; % last command -global STUDY; -global CURRENTSTUDY; -global PLUGINLIST; + %global W_MAIN; % main window + %global H_MAIN; % main window + %global EEGMENU; % main menu + global ALLCOM; % all commands (history) + global LASTCOM; % last command + global STUDY; + global CURRENTSTUDY; + global PLUGINLIST; -if exist('eegplugin_erplab.m') - global ALLERP; % Javier Lopez-Calderon for ERPLAB -end; + if exist('eegplugin_erplab.m') + global ALLERP; % Javier Lopez-Calderon for ERPLAB + global ALLBEST; + global ALLMVPC; + end +end diff --git a/functions/adminfunc/eeg_helpadmin.m b/functions/adminfunc/eeg_helpadmin.m index dcbb54f3e..855ec1a15 100644 --- a/functions/adminfunc/eeg_helpadmin.m +++ b/functions/adminfunc/eeg_helpadmin.m @@ -1,5 +1,8 @@ %Admin functions (adminfunc folder): -% abouteeglab - No help information +% abouteeglab - Script for compiled EEGLAB version about button... +% biosigpathfirst - Add BIOSIG at the beginning of the path... +% biosigpathlast - Add BIOSIG at the end of the path to avoid overloading Matlab functions... +% eeg_cache - Store data in cache with hashcode... % eeg_checkchanlocs - Check the consistency of the channel locations structure... % eeg_checkset - Check the consistency of the fields of an EEG dataset... % eeg_eval - Apply eeglab function to a collection of input datasets... @@ -7,37 +10,56 @@ % eeg_getversion - Obtain EEGLAB version number... % eeg_global - Declare global EEGLAB variables. These variables are... % eeg_helpadmin - Admin functions (adminfunc folder):... -% eeg_helpgui - EEGLAB HELP: Graphic interface builder functions (guifunc folder):... +% eeg_helpgui - Graphic interface builder functions (guifunc folder):... % eeg_helphelp - How to use EEGLAB help. -% eeg_helpmenu - Call the help file for EEGLAB menus... -% eeg_helpmisc - EEGLAB HELP: Miscelaneous functions not used by EEGLAB graphic interface (miscfunc folder):... -% eeg_helppop - EEGLAB HELP: EEGLAB graphic interface functions (popfunc folder):... -% eeg_helpsigproc - EEGLAB HELP: EEGLAB signal processing functions (sigprocfunc folder):... -% eeg_helpstatistics - EEGLAB HELP: EEGLAB statistics functions (statistics folder):... -% eeg_helpstudy - EEGLAB HELP: EEGLAB group processing (STUDY) functions (studyfunc folder):... +% eeg_helpmenu - EEGLAB menus:... +% eeg_helpmisc - Miscellaneous functions not used by EEGLAB graphic interface (miscfunc folder):... +% eeg_helppop - EEGLAB graphic interface functions (popfunc folder):... +% eeg_helpsigproc - EEGLAB signal processing functions (sigprocfunc folder):... +% eeg_helpstatistics - EEGLAB statistics functions (statistics folder):... +% eeg_helpstudy - EEGLAB group processing (STUDY) functions (studyfunc folder):... % eeg_helptimefreq - Frequency functions (timefreqfunc folder):... % eeg_hist - History for EEGLAB dataset. % eeg_options - Eeglab option script... % eeg_optionsbackup - Eeglab option script... % eeg_readoptions - Read EEGLAB memory options file (eeg_options) into a... % eeg_retrieve - Retrieve an EEG dataset from the variable... -% eeg_store - Store specified EEG dataset(s) in the ALLEG variable... +% eeg_store - Store specified EEG dataset(s) in the ALLEEG variable... % eegh - History function. % eeglab_error - Generate an eeglab error. % eeglab_options - Handle EEGLAB options. This script (not function)... % eeglabexefolder - Return the exe folder for EEGLAB. This function is only... +% error_bc - No help information % gethelpvar - Convert a Matlab m-file help-message header... % getkeyval - Get variable value from a 'key', 'val' sequence string. % gettext - This function prints a dialog box on screen and waits for... +% hlp_argstruct2linearcell - Linearize configation output of arg_guipanel... +% intersect_bc - Intersect backward compatible with Matlab versions prior to 2013a... % is_sccn - Returns 1 if computer is located at SCCN (Swartz Center... % iseeglabdeployed - True for EEGLAB compile version and false otherwise... -% ismatlab - No help information -% makehelpmatlab - No help information -% plugin_extract - No help information -% plugin_install - No help information -% plugin_remove - No help information +% ismatlab - True if called from Matlab; false if called from Octave... +% ismember_bc - Ismember backward compatible with Matlab versions prior to 2013a... +% plugin_askinstall - Install EEGLAB plugin from a GUI or command line... +% plugin_extract - Use plugin_menu instead... +% plugin_getweb - Support function to get plugin information from the web... +% plugin_install - Install EEGLAB plugin. Called by PLUGIN_ASKINSTALL. +% plugin_menu - Main function to install EEGLAB plugins... +% plugin_movepath - Given a path to a plugin folder, this function will... +% plugin_remove - Plugin support function to remove plugin... +% plugin_status - Given the name of a plugin(or part of it), returns... +% plugin_uifilter - Support function for plugin_menu... +% plugin_uiupdate - Support function for plugin_menu... +% plugin_urlread - URLREAD Returns the contents of a URL as a string. +% plugin_urlreadwrite - URLREADWRITE A helper function for URLREAD and URLWRITE. +% plugin_urlsize - URLREAD Returns the contents of a URL as a string. +% plugin_urlwrite - URLWRITE Save the contents of a URL to a file. % pop_delset - Delete a dataset from the variable containing... -% pop_editoptions - Edit memory-saving eeglab() options. These are stored in... +% pop_editoptions - Edit memory-saving EEGLAB options. These are stored in... % pop_rejmenu - Main menu for rejecting trials in an EEG dataset... % pop_stdwarn - Check memory options and issue warning for studies. +% removepath - Remove all path with a given parent path... +% setdiff_bc - Setdiff backward compatible with Matlab versions prior to 2013a... +% troubleshooting_data_formats - Several EEGLAB plugins (not included by default) are available to import... +% union_bc - Union backward compatible with Matlab versions prior to 2013a... +% unique_bc - Unique backward compatible with Matlab versions prior to 2013a... % vararg2str - Transform arguments into string for evaluation... diff --git a/functions/adminfunc/eeg_helpgui.m b/functions/adminfunc/eeg_helpgui.m index b4839170f..d2c6d3211 100644 --- a/functions/adminfunc/eeg_helpgui.m +++ b/functions/adminfunc/eeg_helpgui.m @@ -7,4 +7,4 @@ % pophelp - Same as matlab HTHELP but does not crash under windows. % questdlg2 - Questdlg function clone with coloring and help for... % supergui - A comprehensive gui automatic builder. This function help... -% warndlg2 - Same as warndlg for eeglab()... +% warndlg2 - Same as warndlg for EEGLAB... diff --git a/functions/adminfunc/eeg_helphelp.m b/functions/adminfunc/eeg_helphelp.m index f753b6ab8..32c0eef76 100644 --- a/functions/adminfunc/eeg_helphelp.m +++ b/functions/adminfunc/eeg_helphelp.m @@ -1,4 +1,4 @@ -% eeg_helphelp() - How to use EEGLAB help. +% EEG_HELPHELP - How to use EEGLAB help. % % EEGLAB MENU: % Each EEGLAB menu item calls a Matlab function from the commandline. If this @@ -14,9 +14,9 @@ % The advantage of this process is that the same function can be called in % two ways, either in interactive (pop_) mode or directly from the commandline. % This trick allows EEGLAB to build a history of the commands run under an -% EEGLAB session. (See the eegh() function for details). The command history allows +% EEGLAB session. (See the EEGH function for details). The command history allows % users to build their own EEGLAB macros by copying and pasting commands from -% the EEGLAB history (using eegh() and pop_saveh()) into new Matlab script files. +% the EEGLAB history (using EEGH and POP_SAVEH) into new Matlab script files. % % EEGLAB HELP WINDOWS: % The help message of any function may be called from from the EEGLAB menu @@ -25,23 +25,34 @@ % data (in particular, the 'pop_' functions). To understand their use, look % at the help message for the (non-pop) function they call which actually % processes the data. For example, the menu item % "Plot > Channel ERP image" -% calls the function 'pop_erpimage()'. This function in turn serves as a -% graphic user interface for the computing and plotting function 'erpimage()'. +% calls the function 'POP_ERPIMAGE'. This function in turn serves as a +% graphic user interface for the computing and plotting function 'ERPIMAGE'. % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. help eeg_helphelp diff --git a/functions/adminfunc/eeg_helpmisc.m b/functions/adminfunc/eeg_helpmisc.m index 05306ebd0..469c43b25 100644 --- a/functions/adminfunc/eeg_helpmisc.m +++ b/functions/adminfunc/eeg_helpmisc.m @@ -1,13 +1,14 @@ -%Miscelaneous functions not used by EEGLAB graphic interface (miscfunc folder): +%Miscellaneous functions not used by EEGLAB graphic interface (miscfunc folder): % abspeak - Find peak amps/latencies in each row of a single-epoch data matrix... % arrow - Draw a line with an arrowhead. % averef - Convert common-reference EEG data to average reference... % caliper - Measure a set of spatial components of a given data epoch relative to... -% chanproj - Make a detailed plot of data returned from plotproj()... +% chanproj - Make a detailed plot of data returned from PLOTPROJ... +% compareeeglabdistrib - Compare EEGLAB distributions... % compdsp - Display standard info figures for a data decomposition... -% compheads - Plot multiple topoplot() maps of ICA component topographies... +% compheads - Plot multiple TOPOPLOT maps of ICA component topographies... % compile_eeglab - Platform compiling script... -% compmap - Plot multiple topoplot() maps of ICA component topographies... +% compmap - Plot multiple TOPOPLOT maps of ICA component topographies... % compplot - Plot a data epoch and maps its scalp topography at a given time... % compsort - Reorder ICA components, first largest to smallest by the size... % convolve - Convolve two matrices (normalize by the sum of convolved... @@ -19,55 +20,58 @@ % del2map - Compute the discrete laplacian of an EEG distribution. % dendhier - DENDHIER: Recursive algorithm to find links and distance coordinates on a... % dendplot - DENDPLOT: Plots a dendrogram given a topology matrix. +% detectmalware - This function detects potential malware in the current folder and subfolders... % difftopo - Compute and plot component decomposition for the difference ERP... -% dprime - Signal-detection theory sensitivity measure. % eeg_ms2f - Convert epoch latency in ms to nearest epoch frame number... % eeg_regepochs - Convert a continuous dataset into consecutive epochs of... % eeg_time2prev - Returns a vector giving, for each event of specified ("target") type(s),... -% eegdraw - Subroutine used by eegplotold() to plot data. -% eegdrawg - Subroutine used by eegplotgold() to plot data. +% eegdraw - Subroutine used by EEGPLOTOLD to plot data. +% eegdrawg - Subroutine used by EEGPLOTGOLD to plot data. % eegmovie - Compile and view a Matlab movie. % eegplotgold - Display EEG data in a clinical format... % eegplotold - Display data in a horizontal scrolling fashion... % eegplotsold - Display data in a clinical format without scrolling... % envproj - Plot envelopes of projections of selected ICA component... % erpregout - Regress out the ERP from the data... -% erpregoutfunc - Sub function of erpregout() used to regress... +% erpregoutfunc - Sub function of ERPREGOUT used to regress... % eucl - EUCL: Calculates the euclidean distances among a set of points, or between a... % fastregress - Perform fast regression and return p-value... +% fieldtrip2eeglab - Convert Fieldtrip structures to EEGLAB dataset... % fillcurves - Fill the space between 2 curves... +% findduplicatefunctions - Script to find potential conflict between Matlab functions in the current... % gabor2d - Generate a two-dimensional gabor matrice. % gauss - Return a smooth Gaussian window... % gauss2d - Generate a 2-dimensional gaussian matrix... % gauss3d - Generate a 3-dimensional gaussian matrix... % getallmenus - Get all submenus of a window or a menu and return... +% getallmenuseeglab - Get all submenus of a window or a menu and return... % getipsph - Compute "in place" (m by n) sphering or quasi-sphering matrix for an (n by t)... +% getmfilelist - Recursively get the list of Matlab file in... % gradmap - Compute the gradient of an EEG spatial distribution. % gradplot - Compute the gradient of EEG scalp map(s) on a square grid... -% headmovie - Record a Matlab movie of scalp data. +% headmovie - ########## This function is deprecated. Use eegmovie instead. ##########... % help2html2 - Convert a Matlab m-file help-message header into an .html help file... % helpforexe - Write help files for exe version... % hist2 - Draw superimposed histograms... % hungarian - Solve the assignment problem using the Hungarian method. % icademo - A sample ICA analysis script using the ICA/ERP package... % imagescloglog - Make an imagesc(0) plot with log y-axis and... -% imagesclogy - Make an imagesc(0) plot with log y-axis values (ala semilogy())... -% iscellnumeric - Return 1 if all elements of cell array are numeric... +% imagesclogy - Make an imagesc(0) plot with log y-axis values (ala SEMILOGY)... % kmeans_st - Means clustering of n points into k clusters so that the... % laplac2d - Generate a 2 dimensional gaussian matrice... % lapplot - Compute the discrete laplacian of EEG scalp distribution(s)... -% loadelec - Load electrode names file for eegplot()... +% loadelec - Load electrode names file for EEGPLOT... % loc_subsets - Separate channels into maximally evenly-spaced subsets. -% logimagesc - Make an imagesc(0) plot with log y-axis values (ala semilogy())... +% logimagesc - Make an imagesc(0) plot with log y-axis values (ala SEMILOGY)... % loglike - Log likehood function to estimate dependence between components... % logspec - Plot mean log power spectra of submitted data on loglog scale... % make_timewarp - Select a subset of epochs containing a given event sequence, and return... -% makeelec - Subroutine to make electrode file in eegplot()... +% makeelec - Subroutine to make electrode file in EEGPLOT... % makehelpfiles - Generate function help pages... % makehtml - Generate .html function-index page and function help pages... % mapcorr - Find matching rows in two matrices and their corrs. % matcorr - Find matching rows in two matrices and their corrs. -% matperm - Transpose and sign rows of x to match y (run after matcorr() )... +% matperm - Transpose and sign rows of x to match y (run after MATCORR )... % means - MEANS: Means, standard errors and variances. For column vectors, means(x)... % nan_std - Std, not considering NaN values... % numdim - Estimate a lower bound on the (minimum) number of discrete sources... @@ -78,26 +82,26 @@ % promax - Perform Promax oblique rotation after orthogonal Varimax... % qrtimax - Perform Quartimax rotation of rows of a data matrix. % read_rdf - Read RDF-formatted EEG files. -% readlocsold - Read electrode locations file in style of topoplot() or headplot(). +% readlocsold - Read electrode locations file in style of TOPOPLOT or HEADPLOT. % rmart - Remove eye artifacts from EEG data using regression with... % rmsave - Return the RMS in each channel, epoch... +% rotatematlab - This function calls the Matlab rotate function... % runicalowmem - Perform Independent Component Analysis (ICA) decomposition... % runicatest - Perform Independent Component Analysis (ICA) decomposition... % runpca - Perform principal component analysis (PCA) using singular value... % runpca2 - Perform principal component analysis (PCA) using singular value... % scanfold - Scan folder content... -% seemovie - See an EEG movie produced by eegmovie()... +% seemovie - See an EEG movie produced by EEGMOVIE... % setfont - Change all the fonts properties of a figure. % shortread - Read matrix from short file. % show_events - Display events in epochs. Events selected by... -% testica - Test the runica() function's ability to separate synthetic sources. +% testica - Test the RUNICA function's ability to separate synthetic sources. % textgui - Make sliding vertical window. This window contain text... % tftopo - Generate a figure showing a selected or representative image (e.g.,... % timefrq - Progressive Power Spectral Density estimates on a single... % topoimage - Plot concatenated multichannel time/frequency images... -% tree - Make a hierarchical (tree-diagram) component plot. Use... % tutorial - Bring up the ICA / electrophysiology toolbox tutorial... -% uniqe_cell_string - Array containing only strings, ignores all... +% unique_cell_string - Array containing only strings, ignores all... % uniquef - UNIQUEF: Given a matrix containing group labels, returns a vector containing... % upgma - Group hierarchical cluster analysis of a distance... % varimax - Perform orthogonal Varimax rotation on rows of a data... diff --git a/functions/adminfunc/eeg_helppop.m b/functions/adminfunc/eeg_helppop.m index 68c5d85bb..208bd06a7 100644 --- a/functions/adminfunc/eeg_helppop.m +++ b/functions/adminfunc/eeg_helppop.m @@ -1,11 +1,11 @@ %EEGLAB graphic interface functions (popfunc folder): -% eeg_addnewevents - Eeg_addnewevents() Add new events to EEG structure. Both EEG.event and... +% eeg_addnewevents - EEG_ADDNEWEVENTS Add new events to EEG structure. Both EEG.event and... % eeg_amplitudearea - Resamples an ERP average using spline interpolation... % eeg_chaninds - Look up channel indices in a EEG structure... -% eeg_chantype - Returns the channel indices of the desired channel type(s). % eeg_context - Returns (in output 'delays') a matrix giving, for each event of specified... +% eeg_countepochs - EEG_COUNTEPOCHS Count how many epochs there are of each type... % eeg_decodechan - Given an input EEG dataset structure, output a new EEG data structure... -% eeg_dipselect - Select componet dipoles from an EEG dataset with... +% eeg_dipselect - Select component dipoles from an EEG dataset with... % eeg_eegrej - Reject porition of continuous data in an EEGLAB... % eeg_emptyset - Initialize an EEG dataset structure with default values. % eeg_epoch2continuous - Convert epoched dataset to continuous dataset... @@ -17,6 +17,7 @@ % eeg_getepochevent - Return dataset event field values for all events... % eeg_getica - Get ICA component activation. Recompute if necessary. % eeg_insertbound - Insert boundary event in an EEG event structure. +% eeg_insertboundold - Insert boundary event in an EEG event structure. % eeg_interp - Interpolate data channels... % eeg_laplac - Gives the laplacian for the data contained in EEG... % eeg_lat2point - Convert latencies in time units relative to the... @@ -25,7 +26,7 @@ % eeg_mergechan - Merge channel structure while preserving channel... % eeg_mergelocs - Merge channel structure while preserving channel... % eeg_mergelocs_diffstruct - Merge channel structure while preserving channel... -% eeg_multieegplot - Produce an eegplot() of a the average of an epoched dataset... +% eeg_multieegplot - Produce an EEGPLOT of a the average of an epoched dataset... % eeg_oldica - Report, return or add to oldicaweights and oldicasphere... % eeg_point2lat - Convert latency in data points to latency in ms relative... % eeg_pv - Compute EEG.data 'percent variance ' (pv) of the whole EEG data versus the projections... @@ -37,13 +38,14 @@ % eeg_urlatency - Find the original (ur) latency of a time point in... % getchanlist - Obtain indices of specified channel types. % importevent - Import experimental events from data file or Matlab... +% pop_adjustevents - Adjust event offset of all (or specified) events... % pop_autorej - Perform automatic artifact epoch detection and rejection... % pop_averef - Convert an EEG dataset to average reference. % pop_biosig - Import data files into EEGLAB using BIOSIG toolbox... % pop_biosig16 - Import data files into EEGLAB using BIOSIG toolbox... % pop_biosig16ying - Import data files into EEGLAB using BIOSIG toolbox... % pop_chancenter - Recenter cartesian X,Y,Z channel coordinates... -% pop_chancoresp - Define correspondances between two channel locations structures... +% pop_chancoresp - Define correspondences between two channel locations structures... % pop_chanedit - Edit the channel locations structure of an EEGLAB dataset,... % pop_chanevent - Import event latencies from the rising and/or falling 'edge'... % pop_chansel - Pop up a graphic interface to select channels... @@ -55,7 +57,7 @@ % pop_editeventfield - Add/remove/rename/modify a field in the event structure... % pop_editeventvals - Edit events contained in an EEG dataset structure. % pop_editset - Edit EEG dataset structure fields. -% pop_eegfilt - Interactively filter EEG dataset data using eegfilt()... +% pop_eegfilt - Interactively filter EEG dataset data using EEGFILT... % pop_eegplot - Visually inspect EEG data using a scrolling display. % pop_eegthresh - Reject artifacts by detecting outlier values. This has... % pop_envtopo - Plot envelope of an averaged EEG epoch, plus scalp maps... @@ -67,20 +69,18 @@ % pop_export - Export EEG dataset... % pop_fileio - Import data files into EEGLAB using FileIO... % pop_fileiodir - Import directory into EEGLAB using FileIO... +% pop_findmatchingcomps - Find components with the highest... % pop_headplot - Plot one or more spherically-splined EEG field maps... % pop_icathresh - Main menu for choosing threshold for component... % pop_importdata - Import data from a Matlab variable or disk file by calling... % pop_importegimat - Import EGI Matlab segmented file... % pop_importepoch - Export epoch and/or epoch event information to the event... -% pop_importev2 - Merge a neuroscan EV2 file with input dataset... +% pop_importerplab - Import ERPLAB event list file and bin file into... % pop_importevent - Import events into an EEG dataset. If the EEG dataset... % pop_importpres - Append Presentation event file information into an EEGLAB dataset... % pop_interp - Interpolate data channels... % pop_jointprob - Reject artifacts in an EEG dataset using joint... % pop_loadbci - Import a BCI2000 ascii file into EEGLAB... -% pop_loadcnt - Load a neuroscan CNT file (pop out window if no arguments). -% pop_loaddat - Merge a neuroscan DAT file with input dataset... -% pop_loadeeg - Load a Neuroscan .EEG file (via a pop-up window if no... % pop_loadset - Load an EEG dataset. If no arguments, pop up an input window. % pop_mergeset - Merge two or more datasets. If only one argument is given,... % pop_newcrossf - Return estimates and plots of event-related spectral coherence... @@ -103,19 +103,20 @@ % pop_resample - Resample dataset (pop up window). % pop_rmbase - Remove channel baseline means from an epoched or... % pop_rmdat - Remove continuous data around specific events... -% pop_runica - Run an ICA decomposition of an EEG dataset using runica(),... +% pop_runica - Run an ICA decomposition of an EEG dataset using RUNICA,... % pop_runscript - Run Matlab script... % pop_saveh - Save the EEGLAB session command history stored in ALLCOM... % pop_saveset - Save one or more EEG dataset structures... % pop_select - Given an input EEG dataset structure, output a new EEG data structure... -% pop_selectcomps - Display components with button to vizualize their... +% pop_selectcomps - Display components with button to visualize their... % pop_selectevent - Find events in an EEG dataset. If the dataset... % pop_signalstat - Computes and plots statistical characteristics of a signal,... % pop_snapread - Load an EEG SnapMaster file (pop out window if no arguments). % pop_spectopo - Plot spectra of specified data channels or components. % pop_subcomp - Remove specified components from an EEG dataset. % pop_timef - Returns estimates and plots of event-related (log) spectral... -% pop_timtopo - Call the timtopo() function for epoched EEG datasets. +% pop_timtopo - Call the TIMTOPO function for epoched EEG datasets. +% pop_topochansel - Pop up a topographic interface to select channels... % pop_topoplot - Plot scalp map(s) in a figure window. If number of input... % pop_writeeeg - Write EEGLAB dataset to disk in EDF/GDF or BDF format... % pop_writelocs - Load a EGI EEG file (pop out window if no arguments). diff --git a/functions/adminfunc/eeg_helpsigproc.m b/functions/adminfunc/eeg_helpsigproc.m index fa6e5c280..3f9646eca 100644 --- a/functions/adminfunc/eeg_helpsigproc.m +++ b/functions/adminfunc/eeg_helpsigproc.m @@ -1,10 +1,8 @@ %EEGLAB signal processing functions (sigprocfunc folder): % acsobiro - A. Chickocki's robust Second-Order Blind Identification (SOBI)... -% adjustlocs - Read neuroscan polar location file (.asc)... -% angtimewarp - Given two event marker vectors, computes a... % axcopy - Copy a Matlab figure axis and its graphic objects to a new pop-up window... -% binica - Run stand-alone binary version of runica() from the... -% biosig2eeglab - Convert BIOSIG structue to EEGLAB structure... +% binica - Run stand-alone binary version of RUNICA from the... +% biosig2eeglab - Convert BIOSIG structure to EEGLAB structure... % biosig2eeglabevent - Convert biosig events to EEGLAB event structure... % blockave - Make block average of concatenated data sets of same size... % cart2topo - Convert xyz-cartesian channel coordinates... @@ -15,7 +13,7 @@ % compvar - Project selected components and compute the variance of... % condstat - Accumulate surrogate data for comparing two data conditions... % convertlocs - Convert electrode locations between coordinate systems... -% copyaxis - Helper function for axcopy()... +% copyaxis - Helper function for AXCOPY... % coregister - Co-register measured or template electrode locations with a... % dipoledensity - Compute and optionally plot a measure of the 3-D spatial... % eegfilt - (high|low|band)-pass filter data using two-way least-squares... @@ -25,14 +23,14 @@ % eegplot2trial - Convert EEGPLOT rejections into trial and electrode... % eegplot_readkey - Eegplot helper function to read key strokes... % eegrej - Reject/excise arbitrary periods from continuous EEG data... -% eegthresh - Classical trial rejection rejection using a threshold on... +% eegthresh - Reject trials with out-of-bounds channel values within a... % entropy_rej - Calculation of entropy of a 1D, 2D or 3D array and... % env - Return envelope of rows of a data matrix, or optionally... % envtopo - No help information... % epoch - Extract epochs time locked to specified events from continuous EEG data. % erpimage - Plot a colored image of a collection of single-trial data epochs, optionally... -% eventalign - Function called by pop_importevent() to find the best... -% eventlock - DEPRECATED: Please use eegalign() instead. +% eventalign - Function called by POP_IMPORTEVENT to find the best... +% eventlock - DEPRECATED: Please use EEGALIGN instead. % eyelike - Calculate a permutation matrix P and a scaling (diagonal) maxtrix S... % fastif - Fast if function. % floatread - Read matrix from float file ssuming four byte floating point number... @@ -45,15 +43,11 @@ % icaproj - Project ICA component activations through the... % icavar - Project ICA component activations through the ICA weight matrices... % imagesctc - DEPRECATED. never completed or documented. -% isscript - Function checking if a specific file is a script%... +% isscript - Function checking if a specific file is a script or a function... % jader - Blind separation of real signals using JADE (v1.5, Dec. 1997). % jointprob - Rejection of odd columns of a data array using... % kmeanscluster - Simple k means clustering algorithm... % kurt - Return kurtosis of input data distribution... -% loadavg - Loading eeg average data file from Neuroscan into... -% loadcnt - Load a Neuroscan continuous signal file. -% loaddat - Loading neuroscan format data file into matlab. -% loadeeg - Load a binary data file in Neuroscan .eeg file format. % loadtxt - Load ascii text file into numeric or cell arrays... % lookupchantemplate - Look up channel template. % matsel - Select rows, columns, and epochs from given multi-epoch data matrix... @@ -63,7 +57,6 @@ % moveaxes - Move, resize, or copy Matlab axes using the mouse... % mri3dplot - Plot 3-D density image translucently on top of the mean MR... % nan_mean - Average, not considering NaN values... -% openbdf - Opens an BDF File (European Data Format for Biosignals) in MATLAB (R)... % parsetxt - Parse text input into cell array... % phasecoher - Implements inter-trial amp/coherence using Gaussian wavelets. % plotchans3d - Plots the 3-D configuration from a Polhemus ELP... @@ -73,12 +66,10 @@ % plotmesh - Plot mesh defined by faces and vertex... % plotsphere - This function is used to plot a sphere and... % plottopo - Plot concatenated multichannel data epochs in a topographic... -% posact - Make runica() activations all RMS-positive. +% posact - Make RUNICA activations all RMS-positive. % projtopo - Plot projections of one or more ICA components along with... -% uisettxt - No help information % qqdiagram - Empirical quantile-quantile diagram. % quantile - Computes the quantiles of the data sample from a distribution X... -% readbdf - Loads selected Records of an EDF or BDF File (European Data Format... % readedf - Read eeg data in EDF format. % readeetraklocs - Read 3-D location files saved using the EETrak... % readegi - Read EGI Simple Binary datafile (versions 2,3,4,5,6,7). @@ -86,8 +77,6 @@ % readegilocs - Look up locations for EGI EEG dataset. % readelp - Read electrode locations from an .elp (electrode positions)... % readlocs - Read electrode location coordinates and other information from a file. -% readneurodat - Read neuroscan location file (.dat)... -% readneurolocs - Read neuroscan polar location file (.asc)... % readtxtfile - Read text file into a Matlab variable... % realproba - Compute the effective probability of the value... % rejkurt - Calculation of kutosis of a 1D, 2D or 3D array and... @@ -105,22 +94,19 @@ % slider - Add slider to a figure... % snapread - Read data in Snap-Master Standard Binary Data File Format... % sobi - Second Order Blind Identification (SOBI) by joint diagonalization of... -% spec - Power spectrum. This function replaces psd() function if the signal... -% spectopo - Plot the mean log spectrum of a set of data epochs at all channels... +% spec - Power spectrum. This function replaces PSD function if the signal... +% spectopo - Plot the power spectral density (PSD) of winsize length segments of data... % sph2topo - Convert from a 3-column headplot file in spherical coordinates... % spher - Return the sphering matrix for given input data... -% spherror - Chancenter() sub function to compute minimum distance... +% spherror - CHANCENTER sub function to compute minimum distance... % strmultiline - Format a long string as a multi-line string. % textsc - Places text in screen coordinates and places... -% timefdetails - Details of the timef() function for time/frequency analysis... +% timefdetails - Details of the TIMEF function for time/frequency analysis... % timtopo - Plot all channels of a data epoch on the same axis... -% topo2sph - Convert a topoplot() style 2-D polar-coordinate... +% topo2sph - Convert a TOPOPLOT style 2-D polar-coordinate... % topoplot - Plot a topographic map of a scalp data field in a 2-D circular view... % transformcoords - Select nazion and inion in anatomical MRI images. % trial2eegplot - Convert eeglab format to eeplot format of rejection window... % uigetfile2 - Same as uigetfile but remember folder location. % uiputfile2 - Same as uigputfile but remember folder location. -% voltype - VOLTYPE determines the type of volume conduction model... -% writecnt - Write a Neuroscan continuous signal file. -% writeeeg - Generating CNT/EDF/BDF/GDF-files using BIOSIG toolbox. Note... % writelocs - Write a file containing channel location, type and gain information... diff --git a/functions/adminfunc/eeg_helpstudy.m b/functions/adminfunc/eeg_helpstudy.m index 7fc6a2530..882ae1d72 100644 --- a/functions/adminfunc/eeg_helpstudy.m +++ b/functions/adminfunc/eeg_helpstudy.m @@ -1,12 +1,21 @@ %EEGLAB group processing (STUDY) functions (studyfunc folder): % compute_ersp_times - Computes the widest possible ERSP/ITC time window,... +% eeglabciplot - Eeglabciplot(lower,upper)... +% extractcontrast - AllFactorsStruct = pop_listfactors(STUDY.design)... +% gethashcode - Get hash code for input array... % neural_net - Computes clusters using Matlab Neural Net toolbox. +% pop_addindepvar - Support function for pop_studydesign... % pop_chanplot - Graphic user interface (GUI)-based function with plotting... % pop_clust - Select and run a clustering algorithm on components from an EEGLAB STUDY... % pop_clustedit - Graphic user interface (GUI)-based function with editing and plotting... +% pop_dipparams - Set plotting parameters for dipoles. % pop_erpimparams - Set plotting and statistics parameters for... % pop_erpparams - Set plotting and statistics parameters for cluster ERP... % pop_erspparams - Set plotting and statistics parameters for... +% pop_importgroupvar - Import a group variable from a ASCII file and... +% pop_limo - Prepare and convert EEGLAB data and structure to be... +% pop_limoresults - Deprecated... +% pop_listfactors - List independent variables factors for a given design... % pop_loadstudy - Load an existing EEGLAB STUDY set of EEG datasets plus... % pop_preclust - Prepare STUDY components' location and activity measures for later clustering. % pop_precomp - Precompute measures (spectrum, ERP, ERSP) for a collection of data... @@ -16,20 +25,24 @@ % pop_study - Create a new STUDY set structure defining a group of related EEG datasets. % pop_studydesign - Create a STUDY design structure. % pop_studyerp - Create a simple design for ERP analysis... -% robust_kmeans - An extension of Matlab kmeans() that removes outlier... +% robust_kmeans - An extension of Matlab KMEANS that removes outlier... +% std_apcluster - Affinity propagation cluster for eeglab STUDY... +% std_builddesignmat - Build the design matrix for an specific design... % std_cell2setcomps - Convert .sets and .comps to cell array. The .sets and... % std_centroid - Compute cluster centroid in EEGLAB dataset STUDY. % std_changroup - Create channel groups for plotting. % std_chaninds - Look up channel indices in a STUDY... % std_chantopo - Plot ERP/spectral/ERSP topoplot at a specific... % std_checkconsist - Create channel groups for plotting. +% std_checkdatasession - Check/fill session field in STUDY. Based in the... +% std_checkdesign - Check if STUDY design is compatible with EEGLAB... % std_checkfiles - Check all STUDY files consistency... % std_checkset - Check STUDY set consistency... % std_clustmaxelec - Function to find the electrode with maximum absolute projection... -% std_clustread - This function has been replaced by std_readdata() for... +% std_combtrialinfo - Combine and integrate all the info into the... % std_comppol - Inverse component polarity in a component cluster... -% std_convertdesign - Temporary function converting STUDY design legacy... % std_createclust - Dreate a new empty cluster. After creation, components... +% std_detachplots - Given a figure with subplots and several lines per axis, will add a callback to... % std_dipoleclusters - Plots clusters of ICs as colored dipoles in MRI... % std_dipplot - Commandline function to plot cluster component dipoles. Dipoles for each... % std_editset - Modify a STUDY set structure. @@ -41,14 +54,25 @@ % std_erspplot - Plot STUDY cluster ERSPs. Displays either mean cluster ERSPs,... % std_figtitle - Generate plotting figure titles in a cell array... % std_filecheck - Check if ERSP or SPEC file contain specific parameters. -% std_fileinfo - Check uniform channel distribution accross datasets... +% std_fileinfo - Check uniform channel distribution across datasets... +% std_findgroupvars - Find group vars in STUY structure... % std_findoutlierclust - Determine whether an outlier cluster already exists... % std_findsameica - Find groups of datasets with identical ICA decomposiotions... % std_getdataset - Constructs and returns EEG dataset from STUDY design. % std_getindvar - Get independent variables of a STUDY... +% std_gettrialsind - Return the index of the trials that comply with the... % std_indvarmatch - Match independent variable value in a list of values... % std_interp - Interpolate, if needed, a list of named data channels... % std_itcplot - Commandline function to plot cluster ITCs. Either displays mean cluster... +% std_limo - Export and run in LIMO the EEGLAB STUDY design. +% std_limo_old - Export and run in LIMO the EEGLAB STUDY design. +% std_limocontrast - No help information +% std_limodesign - Create LIMO design matrices for categorical and... +% std_limoerase - Erase LIMO files. +% std_limoresults - Studyset structure containing some or all files in ALLEEG... +% std_limosavedesignfiles - Factors = pop_listfactors(STUDY.design(2), 'gui', 'off');... +% std_lm_getvars - Retrieve categorical or continuous variables from a... +% std_lm_seteegfields - Set limo fields in eeg sets... % std_loadalleeg - Constructs an ALLEEG structure, given the paths and file names... % std_makedesign - Create a new or edit an existing STUDY.design by... % std_maketrialinfo - Create trial information structure using the... @@ -58,20 +82,23 @@ % std_movie - Make movie in the frequency domain... % std_pac - Compute or read PAC data (Phase Amplitude Coupling). % std_pacplot - Commandline function to plot cluster PAC... -% std_plot - This function is outdated. Use std_plottf() to plot time/... +% std_plot - This function is outdated. Use STD_PLOTTF to plot time/... % std_plotcurve - Plot ERP or spectral traces for a STUDY component... +% std_plotdmat - Plot design matrix and info associated with the study for... % std_plottf - Plot ERSP/ITC images a component... % std_preclust - Select measures to be included in computation of a preclustering array. -% std_precomp - Precompute measures (ERP, spectrum, ERSP, ITC) for channels in a... +% std_precomp - Precompute measures (ERP, spectrum, ERSP, ITC) for channels or... % std_precomp_worker - Allow dispatching ERSP to be computed in parallel... % std_prepare_neighbors - Prepare Fieldtrip channel neighbor structure. % std_propplot - Command line function to plot component cluster... % std_pvaf - Compute 'percent variance accounted for' (pvaf) by specified... -% std_readdata - LEGACY FUNCTION, SHOULD NOT BE USED ANYMORE. INSTEAD... +% std_readcustom - Read custom data structure for file save on disk. +% std_readdata - Load measures for data channels or... % std_readerp - Load ERP measures for data channels or... % std_readerpimage - Load ERPimage measures for data channels or... % std_readersp - Load ERSP measures for data channels or for all... % std_readfile - Read data file containing STUDY measures. +% std_readfilelimo - Read limo file into eeglab structure... % std_readitc - Load ITC measures for data channels or... % std_readpac - Read phase-amplitude correlation... % std_readspec - Load spectrum measures for data channels or... @@ -85,18 +112,18 @@ % std_reset - Remove all preloaded measures from STUDY... % std_rmalldatafields - Remove all data fields from STUDY (before saving... % std_savedat - Save measure for computed data... -% std_selcomp - Helper function for std_erpplot(), std_specplot()... +% std_selcomp - Helper function for STD_ERPPLOT, STD_SPECPLOT... % std_selectdataset - Select datasets and trials for a given independent... % std_selectdesign - Select an existing STUDY design. -% std_selsubject - Helper function for std_erpplot(), std_specplot()... -% std_setcomps2cell - Convert .sets and .comps to cell array. The .sets and... +% std_selsubject - Helper function for STD_ERPPLOT, STD_SPECPLOT... +% std_serialize - Convert a MATLAB data structure into a compact byte vector. This function... % std_spec - Returns the ICA component spectra for a dataset. Updates the EEG structure... % std_specgram - Returns the ICA component or channel spectrogram for a dataset. % std_specplot - Plot STUDY component cluster spectra, either mean spectra... % std_stat - Compute statistics for ERP/spectral traces or ERSP/ITC images... % std_substudy - Create a sub-STUDY set by removing datasets, conditions, groups, or... -% std_topo - Uses topoplot() to get the interpolated Cartesian grid of the... +% std_topo - Uses TOPOPLOT to get the interpolated Cartesian grid of the... % std_topoplot - Command line function to plot cluster component and mean scalp maps. -% std_uniformfiles - Check uniform channel distribution accross data files... -% std_uniformsetinds - Check uniform channel distribution accross datasets... -% toporeplot - Re-plot a saved topoplot() output image (a square matrix)... +% std_uniformfiles - Check uniform channel distribution across data files... +% std_uniformsetinds - Check uniform channel distribution across datasets... +% toporeplot - Re-plot a saved TOPOPLOT output image (a square matrix)... diff --git a/functions/adminfunc/eeg_helptimefreq.m b/functions/adminfunc/eeg_helptimefreq.m index e52a4654e..91bc187ba 100644 --- a/functions/adminfunc/eeg_helptimefreq.m +++ b/functions/adminfunc/eeg_helptimefreq.m @@ -1,7 +1,7 @@ %EEGLAB time-frequency functions (timefreqfunc folder): -% angTimeWarp - Given two event marker vectors, angTimeWarp computes a... +% angtimewarp - Given two event marker vectors, computes a... % bootstat - Accumulate surrogate data to assess significance by permutation of some... -% correct_mc - Compute an upper limit for the number of independant... +% correct_mc - Compute an upper limit for the number of independent... % correctfit - Correct fit using observed p-values. Use this function... % crossf - Returns estimates and plots event-related coherence (ERCOH)... % dftfilt - Discrete Fourier filter... @@ -9,13 +9,17 @@ % dftfilt3 - Discrete complex wavelet filters... % newcrossf - Returns estimates and plots event-related coherence (ERCOH)... % newtimef - Return estimates and plots of mean event-related (log) spectral... +% newtimefbaseln - Remove baseline power values for newtimef. This... +% newtimefitc - Function to compute inter-trial coherence (phase locking... +% newtimefpowerunit - Find power unit for y-axis based on input structure. +% newtimeftrialbaseln - Remove baseline power values for single trials in... % pac - Compute phase-amplitude coupling (power of first input... % pac_cont - Compute phase-amplitude coupling (power of first input... % rsadjust - Adjust l-values (Ramberg-Schmeiser distribution)... % rsfit - Find p value for a given value in a given distribution... % rsget - Get the p-value for a given collection of l-values... -% rspdfsolv - Sub-function used by rsfit() to searc for optimal... -% rspfunc - Sub-function used by rsget()... +% rspdfsolv - Sub-function used by RSFIT to searc for optimal... +% rspfunc - Sub-function used by RSGET... % timef - Returns estimates and plots of mean event-related spectral... % timefreq - Compute time/frequency decomposition of data trials. This... % timewarp - Given two event marker vectors, computes a matrix... diff --git a/functions/adminfunc/eeg_hist.m b/functions/adminfunc/eeg_hist.m index 0d13eb94d..fe9ec419b 100644 --- a/functions/adminfunc/eeg_hist.m +++ b/functions/adminfunc/eeg_hist.m @@ -1,4 +1,4 @@ -% eeg_hist() - history for EEGLAB dataset. +% EEG_HIST - history for EEGLAB dataset. % % Usage: % >> EEGOUT = eeg_hist( EEGIN, command ); @@ -7,43 +7,51 @@ % EEGIN - input dataset % command - [string] eeglab command % -% Global variables used: -% EEGOUT - output dataset with updated history field -% % Author: Arnaud Delorme, SCCN/INC/UCSD, Dec 2003 % -% See also: eegh(), eeglab() +% See also: EEGH, EEGLAB % Copyright (C) 2003 Arnaud Delorme, SCCN/INC/UCSD, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 = eeg_hist( EEG, command ); +function EEG = eeg_hist( EEG, command ) if nargin < 2 help eeg_hist; -end; +end if ~isfield(EEG, 'history') EEG.history = ''; -end; +end -if ~isempty(command) +if ~isempty(command) && isempty(strfind(command, 'pop_loadset')) try EEG.history = [ EEG.history 10 command ]; catch EEG.history = strvcat(EEG.history, command); - end; -end; + end +end diff --git a/functions/adminfunc/eeg_options.m b/functions/adminfunc/eeg_options.m index 77f418802..b865f1353 100644 --- a/functions/adminfunc/eeg_options.m +++ b/functions/adminfunc/eeg_options.m @@ -1,6 +1,6 @@ -% eeg_options() - eeglab option script +% EEG_OPTIONS - eeglab option script % -% Note: DO NOT EDIT, instead use pop_editoptions() or the menu +% Note: DO NOT EDIT, instead use POP_EDITOPTIONS or the menu % /File/Maximize memory in EEGLAB gui % STUDY options (set these checkboxes if you intend to work with studies) diff --git a/functions/adminfunc/eeg_options.txt b/functions/adminfunc/eeg_options.txt new file mode 100644 index 000000000..ebd01b8b1 --- /dev/null +++ b/functions/adminfunc/eeg_options.txt @@ -0,0 +1,16 @@ +% eeg_options.txt - eeglab option script for the EEGLAB compiled version +% +% Note: DO NOT EDIT, instead use pop_editoptions() or the menu +% /File/Maximize memory in EEGLAB gui + +% STUDY options (set these checkboxes if you intend to work with studies) +option_storedisk = 0 ; % If set, keep at most one dataset in memory. This allows processing hundreds of datasets within studies. +option_savetwofiles = 1 ; % If set, save not one but two files for each dataset (header and data). This allows faster data loading in studies. +% Memory options +option_single = 1 ; % If set, use single precision under Matlab 7.x. This saves RAM but can lead to rare numerical imprecisions. +option_memmapdata = 0 ; % If set, use memory mapped array under Matlab 7.x. This may slow down some computation. +% ICA options +option_computeica = 0 ; % If set, precompute ICA activations. This requires more RAM but allows faster plotting of component activations. +option_scaleicarms = 1 ; % If set, scale ICA component activities to RMS (Root Mean Square) in microvolt (recommended). +% Folder options +option_rememberfolder = 1 ; % If set, when browsing to open a new dataset assume the folder/directory of previous dataset. diff --git a/functions/adminfunc/eeg_optionsbackup.m b/functions/adminfunc/eeg_optionsbackup.m index 408ae76aa..c5b24151d 100644 --- a/functions/adminfunc/eeg_optionsbackup.m +++ b/functions/adminfunc/eeg_optionsbackup.m @@ -1,23 +1,30 @@ -% eeg_options() - eeglab option script +% EEG_OPTIONS - eeglab option script % -% Note: DO NOT EDIT, instead use pop_editoptions() or the menu +% Note: DO NOT EDIT, instead use POP_EDITOPTIONS or the menu % /File/Maximize memory in EEGLAB gui -% STUDY and file options (set these checkboxes if you intend to work with studies) +% STUDY and file options (set the first checkbox if you intend to work with studies) option_storedisk = 0 ; % If set, keep at most one dataset in memory. This allows processing hundreds of datasets within studies. -option_savetwofiles = 1 ; % If set, save not one but two files for each dataset (header and data). This allows faster data loading in studies. -option_saveversion6 = 1 ; % If set, write Matlab files in Matlab v6.5 (max compatibility). If not, write files in Matlab v7.3 (larger than 2Gb). +option_savetwofiles = 0 ; % If set, save not one but two files for each dataset (header and data). No longer set by default as of 2021. +option_saveversion6 = 1 ; % If set, write files in Matlab v6.5 (fastest and Octave compatible). If not, write files in Matlab v7.3 (for files > 2Gb). +option_saveasstruct = 1 ; % If set, save the fields of the EEG structure as individual variables in the file (new 2021 default). +option_parallel = 0 ; % If set, use the parallel toolbox when processing multiple datasets (beta) % Memory options -option_single = 1 ; % If set, use single precision under Matlab 7.x. This saves RAM but can lead to rare numerical imprecisions. +option_single = 1 ; % If set, use single precision number (32-bit instead of 64-bit) in memory. option_memmapdata = 0 ; % If set, use memory mapped array under Matlab 7.x. This may slow down some computation (beta). option_eegobject = 0 ; % If set, use the EEGLAB EEG object instead of the standard EEG structure (beta). % ICA options option_computeica = 1 ; % If set, precompute ICA activations. This requires more RAM but allows faster plotting of component activations. option_scaleicarms = 1 ; % If set, scale ICA component activities to RMS (Root Mean Square) in microvolt (recommended). % Folder options -option_rememberfolder = 1 ; % If set, when browsing to open a new dataset assume the folder/directory of previous dataset. +option_rememberfolder = 1 ; % If set, when browsing to open a new dataset assume the folder/directory of the previous dataset. % Toolbox options option_donotusetoolboxes = 0 ; % If set, do not use Matlab additional toolboxes functions even if they are present (need to restart EEGLAB). % EEGLAB connectivity and support -option_checkversion = 1 ; % If set, check for new version of EEGLAB at startup. -option_chat = 0 ; % If set, enable EEGLAB chat - currently UCSD only - restart EEGLAB after changing that option. +option_showadvanced = 0 ; % If set, show advanced options (close and reopen this GUI to effect changes) +option_boundary99 = 0 ; % If set, use type "-99" for boundary events when processing numerical event types (ERPLAB compatibility) +option_showpendingplugins = 0 ; % If set, show plugins pending approval instead of approved plugins (for developers only) +option_allmenus = 0 ; % If set, show all menu items from previous EEGLAB versions. You must restart EEGLAB for this to take effect. +option_htmlingraphics = 1 ; % If set, allow HTML in graphics (can be slow on Windows). +option_checkversion = 1 ; % If set, check for new version of EEGLAB and EEGLAB extensions at startup. +option_cachesize = 500 ; % Size of cache in Mbytes for EEGLAB STUDY cache in RAM. diff --git a/functions/adminfunc/eeg_optionsbackup.txt b/functions/adminfunc/eeg_optionsbackup.txt new file mode 100644 index 000000000..6d70a1f9b --- /dev/null +++ b/functions/adminfunc/eeg_optionsbackup.txt @@ -0,0 +1,24 @@ +% eeg_optionsbackup - eeglab option script for the EEGLAB compiled version +% +% Note: DO NOT EDIT, instead use pop_editoptions() or the menu +% /File/Maximize memory in EEGLAB gui + +% STUDY and file options (set these checkboxes if you intend to work with studies) +option_storedisk = 0 ; % If set, keep at most one dataset in memory. This allows processing hundreds of datasets within studies. +option_savetwofiles = 1 ; % If set, save not one but two files for each dataset (header and data). This allows faster data loading in studies. +option_saveversion6 = 1 ; % If set, write Matlab files in Matlab v6.5 (max compatibility). If not, write files in Matlab v7.3 (larger than 2Gb). +% Memory options +option_single = 1 ; % If set, use single precision number (32-bit instead of 64-bit) in memory. +option_memmapdata = 0 ; % If set, use memory mapped array under Matlab 7.x. This may slow down some computation (beta). +option_eegobject = 0 ; % If set, use the EEGLAB EEG object instead of the standard EEG structure (beta). +% ICA options +option_computeica = 1 ; % If set, precompute ICA activations. This requires more RAM but allows faster plotting of component activations. +option_scaleicarms = 1 ; % If set, scale ICA component activities to RMS (Root Mean Square) in microvolt (recommended). +% Folder options +option_rememberfolder = 1 ; % If set, when browsing to open a new dataset assume the folder/directory of previous dataset. +% Toolbox options +option_donotusetoolboxes = 0 ; % If set, do not use Matlab additional toolboxes functions even if they are present (need to restart EEGLAB). +% EEGLAB connectivity and support +option_checkversion = 1 ; % If set, check for new version of EEGLAB at startup. +option_chat = 0 ; % If set, enable EEGLAB chat - currently UCSD only - restart EEGLAB after changing that option. +option_cachesize = 100 ; % Size of cache in Mbytes for EEGLAB STUDY cache in RAM. diff --git a/functions/adminfunc/eeg_readoptions.m b/functions/adminfunc/eeg_readoptions.m index 25596c0f6..e86359452 100644 --- a/functions/adminfunc/eeg_readoptions.m +++ b/functions/adminfunc/eeg_readoptions.m @@ -1,4 +1,4 @@ -% eeg_readoptions() - Read EEGLAB memory options file (eeg_options) into a +% EEG_READOPTIONS - Read EEGLAB memory options file (eeg_options) into a % structure variable (opt). % % Usage: @@ -17,39 +17,50 @@ % % Author: Arnaud Delorme, SCCN, INC, UCSD, 2006- % -% See also: eeg_options(), eeg_editoptions() +% See also: EEG_OPTIONS, EEG_EDITOPTIONS % Copyright (C) Arnaud Delorme, SCCN, INC, UCSD, 2006- % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [ header, opt ] = eeg_readoptions( filename, opt_backup ); if nargin < 1 help eeg_readoptions; return; - end; + end if nargin < 2 opt_backup = []; - end; + end - if isstr(filename) + if ischar(filename) fid = fopen(filename, 'r'); else fid = filename; - end; + end % skip header % ----------- @@ -58,7 +69,7 @@ while (str(1) == '%') header = [ header str]; str = fgets( fid ); - end; + end % read variables values and description % -------------------------------------- @@ -79,11 +90,11 @@ dsc = deblank( dsc(end:-1:1) ); opt(index).description = deblank( dsc(end:-1:1) ); opt(index).value = str2num( opt(index).value ); - end; + end str = fgets( fid ); % jump a line index = index+1; - end; + end fclose(fid); % replace in backup structure if any @@ -92,10 +103,10 @@ if ~isempty(opt) for index = 1:length(opt_backup) ind = strmatch(opt_backup(index).varname, { opt.varname }, 'exact'); - if ~isempty(ind) & ~isempty(opt_backup(index).varname) + if ~isempty(ind) && ~isempty(opt_backup(index).varname) opt_backup(index).value = opt(ind).value; - end; - end; - end; + end + end + end opt = opt_backup; - end; + end diff --git a/functions/adminfunc/eeg_retrieve.m b/functions/adminfunc/eeg_retrieve.m index e24ee0286..7980c0fdf 100644 --- a/functions/adminfunc/eeg_retrieve.m +++ b/functions/adminfunc/eeg_retrieve.m @@ -1,4 +1,4 @@ -% eeg_retrieve() - Retrieve an EEG dataset from the variable +% EEG_RETRIEVE - Retrieve an EEG dataset from the variable % containing all datasets (standard: ALLEEG). % % Usage: >> EEG = eeg_retrieve( ALLEEG, index ); @@ -13,27 +13,38 @@ % CURRENTSET - workspace variable index of the current dataset % % Note: The function performs >> EEG = ALLEEG(index); -% It also runs eeg_checkset() on it. +% It also runs EEG_CHECKSET on it. % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % -% See also: eeg_store(), eeglab() +% See also: EEG_STORE, EEGLAB % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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, ALLEEG, CURRENTSET] = eeg_retrieve( ALLEEG, CURRENTSET); @@ -50,15 +61,15 @@ tmpsaved = { ALLEEG.saved }; tmpsaved = tmpsaved(CURRENTSET); catch, tmpsaved = 'no'; - end; + end - if length(CURRENTSET) > 1 & option_storedisk + if length(CURRENTSET) > 1 && option_storedisk [ EEG tmpcom ] = eeg_checkset(ALLEEG(CURRENTSET)); % do not load data if several datasets if length(CURRENTSET) ~= length(ALLEEG) [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); else ALLEEG = EEG; - end; + end else if CURRENTSET ~= 0 [ EEG tmpcom ] = eeg_checkset(ALLEEG(CURRENTSET), 'loaddata'); @@ -66,20 +77,20 @@ else EEG = eeg_emptyset; % empty dataset return; - end; - end; + end + end % retain saved field % ------------------ for index = 1:length(CURRENTSET) ALLEEG(CURRENTSET(index)).saved = tmpsaved{index}; EEG(index).saved = tmpsaved{index}; - end; + end %catch % fprintf('Warning: cannot retrieve dataset with index %d\n', CURRENTSET); % return; -%end; +%end return; diff --git a/functions/adminfunc/eeg_store.m b/functions/adminfunc/eeg_store.m index 363ea54c3..82121ddd0 100644 --- a/functions/adminfunc/eeg_store.m +++ b/functions/adminfunc/eeg_store.m @@ -1,6 +1,6 @@ -% eeg_store() - store specified EEG dataset(s) in the ALLEG variable +% EEG_STORE - store specified EEG dataset(s) in the ALLEEG variable % containing all current datasets, after first checking -% dataset consistency using eeg_checkset(). +% dataset consistency using EEG_CHECKSET. % % Usage: >> [ALLEEG EEG index] = eeg_store(ALLEEG, EEG); % >> [ALLEEG EEG index] = eeg_store(ALLEEG, EEG, index); @@ -11,7 +11,7 @@ % May also be an array of datasets; these will be % checked and stored separately in ALLEEG. % index - (optional), ALLEEG index (or indices) to use to store -% the new dataset(s). If no index is given, eeg_store() +% the new dataset(s). If no index is given, EEG_STORE % uses the lowest empty slot(s) in the ALLEEG array. % Outputs: % ALLEEG - array of all current datasets @@ -30,64 +30,73 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % -% See also: eeglab(), eeg_checkset(), eeg_retrieve() +% See also: EEGLAB, EEG_CHECKSET, EEG_RETRIEVE % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -% uses the global variable EEG ALLEEG CURRENTSET +% 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. % store set % ------------------ -function [ALLEEG, EEG, storeSetIndex] = eeg_store(ALLEEG, EEG, storeSetIndex, varargin); +function [ALLEEG, EEG, storeSetIndex] = eeg_store(ALLEEG, EEG, storeSetIndex, varargin) % check parameter consistency % ------------------------------ if nargin >= 3 - if length(EEG) ~= length(storeSetIndex) & storeSetIndex(1) ~= 0 + if length(EEG) ~= length(storeSetIndex) && storeSetIndex(1) ~= 0 error('Length of input dataset structure must equal the length of the index array'); - end; -end; + end +end % considering multiple datasets % ----------------------------- if length(EEG) > 1 TMPEEG = EEG; - if nargin >= 3 & storeSetIndex(1) ~= 0 + if nargin >= 3 && storeSetIndex(1) ~= 0 for index=1:length(TMPEEG) EEG = TMPEEG(index); tmpsaved = EEG.saved; - if strcmpi(tmpsaved, 'justloaded'), tmpsaved = 'yes'; end; + if strcmpi(tmpsaved, 'justloaded'), tmpsaved = 'yes'; end [ALLEEG, EEG] = eeg_store(ALLEEG, EEG, storeSetIndex(index), varargin{:}); ALLEEG(storeSetIndex(index)).saved = tmpsaved; TMPEEG(index).saved = tmpsaved; - end; + end else for index=1:length(TMPEEG) EEG = TMPEEG(index); tmpsaved = EEG.saved; - if strcmpi(tmpsaved, 'justloaded'), tmpsaved = 'yes'; end; + if strcmpi(tmpsaved, 'justloaded'), tmpsaved = 'yes'; end [ALLEEG, EEG, storeSetIndex(index)] = eeg_store(ALLEEG, EEG); ALLEEG(storeSetIndex(index)).saved = tmpsaved; TMPEEG(index).saved = tmpsaved; - end; - end; + end + end EEG = TMPEEG; - return; -end; + return +end if nargin < 3 % creating new dataset @@ -96,24 +105,24 @@ EEG.filename = ''; EEG.filepath = ''; EEG.datfile = ''; -end; +end if isempty(varargin) % no text output and no check (study loading) - [ EEG com ] = eeg_checkset(EEG); + [ EEG, com ] = eeg_checkset(EEG); else com = ''; -end; -if nargin > 2, +end +if nargin > 2 if storeSetIndex == 0 || strcmpi(EEG.saved, 'justloaded') EEG.saved = 'yes'; % just loaded else EEG.saved = 'no'; - end; + end elseif strcmpi(EEG.saved, 'justloaded') EEG.saved = 'yes'; else EEG.saved = 'no'; -end; +end EEG = eeg_hist(EEG, com); % find first free index @@ -121,28 +130,28 @@ findindex = 0; if nargin < 3, findindex = 1; elseif storeSetIndex == 0, findindex = 1; -end; +end if findindex i = 1; - while (i<2000) + while (i<10000) try - if isempty(ALLEEG(i).data); - storeSetIndex = i; i = 2000; - end; + if isempty(ALLEEG(i).data) + storeSetIndex = i; i = 10000; + end i = i+1; catch - storeSetIndex = i; i = 2000; - end; - end; + storeSetIndex = i; i = 10000; + end + end if isempty(varargin) % no text output and no check fprintf('Creating a new ALLEEG dataset %d\n', storeSetIndex); - end; + end else - if isempty(storeSetIndex) | storeSetIndex == 0 + if isempty(storeSetIndex) || storeSetIndex == 0 storeSetIndex = 1; - end; -end; + end +end if ~isempty( ALLEEG ) try @@ -150,12 +159,12 @@ catch allfields = fieldnames( EEG ); for i=1:length( allfields ) - eval( ['ALLEEG(' int2str(storeSetIndex) ').' allfields{i} ' = EEG.' allfields{i} ';' ]); - end; - if ~isfield(EEG, 'datfile') & isfield(ALLEEG, 'datfile') + ALLEEG(storeSetIndex).(allfields{i}) = EEG.(allfields{i}); + end + if ~isfield(EEG, 'datfile') && isfield(ALLEEG, 'datfile') ALLEEG(storeSetIndex).datfile = ''; - end; - end; + end + end else ALLEEG = EEG; if storeSetIndex ~= 1 @@ -163,6 +172,5 @@ ALLEEG(1) = ALLEEG(storeSetIndex); % empty ALLEEG(storeSetIndex) = ALLEEG(storeSetIndex+1); ALLEEG = ALLEEG(1:storeSetIndex); - end; -end; -return; + end +end diff --git a/functions/adminfunc/eegh.m b/functions/adminfunc/eegh.m index 703783a65..9a9fa69bb 100644 --- a/functions/adminfunc/eegh.m +++ b/functions/adminfunc/eegh.m @@ -1,4 +1,4 @@ -% eegh() - history function. +% EEGH - history function. % % Usage: % >> eegh( arg ); @@ -24,29 +24,40 @@ % Author: Arnaud Delorme, SCCN/INC/UCSD, 2001 % % See also: -% eeglab() (a graphical interface for eeg plotting, space frequency +% EEGLAB (a graphical interface for eeg plotting, space frequency % decomposition, ICA, ... under Matlab for which this command % was designed). % Copyright (C) 2001 Arnaud Delorme, SCCN/INC/UCSD, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % To increase/decrease the maximum depth of the stack, edit the eeg_consts file -function str = eegh( command, str ); +function str = eegh( command, str ) mode = 1; % mode = 1, full print, mode = 0, truncated print @@ -56,37 +67,37 @@ % fprintf('2: %s\n', command); %elseif nargin == 1 % fprintf('1: %s\n', command); -%end; +%end if nargin < 1 if isempty(ALLCOM) fprintf('No history\n'); else - for index = 1:length(ALLCOM) - if mode == 0, txt = ALLCOM{ index }; fprintf('%d: ', index); - else txt = ALLCOM{ length(ALLCOM)-index+1 }; - end; - if (length(txt) > 72) & (mode == 0) - fprintf('%s...\n', txt(1:70) ); - else - fprintf('%s\n', txt ); - end; - end; - end; + for index = 1:length(ALLCOM) + if mode == 0, txt = ALLCOM{ index }; fprintf('%d: ', index); + else txt = ALLCOM{ length(ALLCOM)-index+1 }; + end + if (length(txt) > 72) && (mode == 0) + fprintf('%s...\n', txt(1:70) ); + else + fprintf('%s\n', txt ); + end + end + end if nargout > 0 str = strvcat(ALLCOM); - end; + end elseif nargin == 1 if isempty( command ) return; - end; - if isstr( command ) - if ~isempty(ALLCOM) && isequal(ALLCOM{1}, command), return; end; + end + if ischar( command ) + if ~isempty(ALLCOM) && isequal(ALLCOM{1}, command), return; end if isempty(ALLCOM) ALLCOM = { command }; else ALLCOM = { command ALLCOM{:}}; - end; + end global LASTCOM; LASTCOM = command; else @@ -100,12 +111,12 @@ fprintf('%s...\n', txt(1:70) ); else fprintf('%s\n', txt ); - end; + end evalin( 'base', ALLCOM{command} ); % execute element eegh( ALLCOM{command} ); % add to history - end; - end; - end; + end + end + end else % nargin == 2 if ~isstruct(str) if strcmp(command, 'find') @@ -113,13 +124,13 @@ if ~isempty(findstr(ALLCOM{index}, str)) str = ALLCOM{index}; return; - end; - end; + end + end str = []; - end; + end else % warning also some code present in eeg_store and pop_newset - if ~isempty(ALLCOM) && isequal(ALLCOM{1}, command), return; end; + if ~isempty(ALLCOM) && isequal(ALLCOM{1}, command), return; end eegh(command); % add to history if ~isempty(command) if length(str) == 1 @@ -127,10 +138,10 @@ else for i = 1:length(str) str(i) = eeg_hist(str(i), [ '% multiple datasets command: ' command ]); - end; - end; - end; - end; -end; + end + end + end + end +end diff --git a/functions/adminfunc/eeglab_error.m b/functions/adminfunc/eeglab_error.m index 1a1ea3d35..8c24f9fb4 100644 --- a/functions/adminfunc/eeglab_error.m +++ b/functions/adminfunc/eeglab_error.m @@ -1,4 +1,4 @@ -% eeglab_error() - generate an eeglab error. +% EEGLAB_ERROR - generate an eeglab error. % % Usage: >> eeglab_error; % @@ -6,23 +6,34 @@ % % Author: Arnaud Delorme, SCCN, INC, UCSD, 2006- % -% see also: eeglab() +% see also: EEGLAB % Copyright (C) 2006 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 eeglab_error @@ -33,30 +44,34 @@ ft_error = false; if iseeglaberror tmp = lasterror; % Add more information to eeglab errors JRI, RMC - tmplasterr = sprintf('%s,\n\n (Error occurred in function %s() at line %d)',... - tmplasterr, tmp.stack(1).name, tmp.stack(1).line); + if ~isempty(tmp.stack) + tmplasterr = sprintf('%s,\n\nThis is not a bug (Error occurred in function %s() at line %d)',... + tmplasterr, tmp.stack(1).name, tmp.stack(1).line); + else + tmplasterr = sprintf('%s,\n', tmplasterr); + end errordlg2(tmplasterr, header); else try tmp = lasterror; if length(tmp.stack(1).name) && all(tmp.stack(1).name(1:3) == 'ft_') ft_error = true; - end; + end tmperr = [ 'EEGLAB error in function ' tmp.stack(1).name '() at line ' int2str(tmp.stack(1).line) ':' 10 10 lasterr ]; catch % Matlab 5 and when the stack is empty tmperr = [ 'EEGLAB error:' 10 10 tmplasterr ]; - end; + end if ~ft_error tmperr = [ tmperr 10 10 'If you think this is a bug, please submit a detailed ' 10 ... 'description of how to reproduce the problem (and upload' 10 ... - 'a small dataset) at http://sccn.ucsd.edu/eeglab/bugzilla' ]; + 'a small dataset) at https://github.com/sccn/eeglab/issues' ]; else tmperr = [ tmperr 10 10 'This is a problem with FIELDTRIP. The Fieldtrip version you downloaded' 10 ... 'is corrupted. Please manually replace Fieldtrip with an earlier version' 10 ... - 'and/or email the Fieldtrip developpers so they can fix the issue.' ]; - end; + 'and/or email the Fieldtrip developers so they can fix the issue.' ]; + end errordlg2(tmperr, header); - end; + end function [ val str header ] = testeeglaberror(str) header = 'EEGLAB error'; @@ -69,6 +84,6 @@ funcname = str(1:indendofline(1)-1); str = str(indendofline(1)+1:end); header = [ funcname ' error' ]; - end; + end catch - end; \ No newline at end of file + end diff --git a/functions/adminfunc/eeglab_execmenu.m b/functions/adminfunc/eeglab_execmenu.m new file mode 100644 index 000000000..24a3b56c9 --- /dev/null +++ b/functions/adminfunc/eeglab_execmenu.m @@ -0,0 +1,101 @@ +% EEGLAB_EXECMENU - function called to execute EEGLAB menu +% +% Usage: +% eeglab_execmenu(label, func, parameter); +% +% Inputs: +% label - [string] label of the menu +% func - [string] name of the pop function. The function extract the +% callback from the menu, find the function and add the +% paramters below before executing the callback. +% parameter - [cell] paramter to the function (in addition to existing +% parameters. +% +% Output: the command is executed in the global workspace. Usually the +% EEG structure is affected. +% +% Author: Arnaud Delorme, SCCN/INC/UCSD, 2022 +% +% See also: EEGLAB + +% Copyright (C) 2022 Arnaud Delorme +% +% 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 eeglab_execmenu(label, func, parameters) + +if nargin < 3 + fprintf(2, 'This function requires 3 inputs\n') + help eeglab_execmenu; + return +end + +% find figure +W_MAIN = findobj('tag', 'EEGLAB'); +if isempty(W_MAIN) + error('EEGLAB figure not found'); +end + +% find menu +menuhandle = findobj(W_MAIN, 'Label', label); +if isempty(menuhandle) + error('Could not find menu with label ''%s''', label); +end + +% check if menu contains command +cb = get(menuhandle, 'callback'); +if iscell(cb) + if contains(cb{1}, func) + cb = cb{1}; + else + cb = cb{end}; + end +end +ind = strfind(cb, func); +if length(ind) ~= 1 + fprintf(2, 'Menu with label ''%s'' found, but the callback does not contain the string ''%s''\n', label, func); + ind = ind(end); +end + +% extract callback and add parameters +if ~isempty(parameters) + if cb(ind+length(func)) == ';' + cb = [ cb(1:ind+length(func)-1) '()' cb(ind+length(func):end) ]; + end + indEnd = find(cb(ind:end) == ')'); + indEnd = indEnd(1); + if cb(ind+indEnd-2) == '(' % no parameter before + addDelim = ''; + else + addDelim = ','; + end + cb = [cb(1:ind+indEnd-2) addDelim vararg2str(parameters) cb(ind+indEnd-1) cb(ind+indEnd:end)]; +end + +% execute in global workspace (as menu would) +evalin('base', 'DEBUG_EEGLAB_MENUS = true;'); +evalin('base', cb); +evalin('base', 'clear DEBUG_EEGLAB_MENUS;'); diff --git a/functions/adminfunc/eeglab_new.m b/functions/adminfunc/eeglab_new.m new file mode 100644 index 000000000..f5ecf27c0 --- /dev/null +++ b/functions/adminfunc/eeglab_new.m @@ -0,0 +1,74 @@ +% EEGLAB_NEW - script called when a new dataset is created and require +% input from user. Use workspace variables EEG, ALLEEG, +% CURRENTSET, LASTCOM +% +% Author: Arnaud Delorme, SCCN/INC/UCSD, 2022 +% +% See also: EEGLAB + +% Copyright (C) 2022 Arnaud Delorme +% +% 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. + +% functions below modify the current dataset, but should not create new datasets +functionsEEGLAB = { 'pop_chanedit' 'pop_editset' 'pop_comment' 'pop_headplot' 'pop_selectcomps' ... + 'pop_runica' 'pop_editeventfield' 'pop_editeventvals' 'pop_adjustevents' ... + 'pop_saveset' 'pop_importepoch' 'pop_importevent' 'pop_chanevent' ... + 'pop_importpres' 'pop_importerplab' 'pop_iclabel' 'pop_icflag' 'pop_dipfit_headmodel' ... + 'pop_dipfit_settings' 'pop_dipfit_gridsearch' 'pop_dipfit_nonlinear' 'pop_multifit' 'pop_leadfield' 'topoplot' ';;;' ... + 'pop_roi_connect' 'pop_roi_activity'}; + +posEqual = find('=' == LASTCOM); +if ~isempty(LASTCOM) && ~isempty(EEG) ... + && ~isempty(posEqual) ... + && contains(LASTCOM(1:posEqual(1)), 'EEG') ... % when no equal sign found, do not create new datasets + && ~contains(LASTCOM, functionsEEGLAB) ... % when using one of the functions in the list, do not create new datasets + && ~exist('DEBUG_EEGLAB_MENUS', 'var') % when in debug menu mode, do not create new datasets (see eeglab_execmenu) + + % Here the dataset was modified + EEG = eegh(LASTCOM, EEG); + [ALLEEG, EEG, CURRENTSET, LASTCOM] = pop_newset(ALLEEG, EEG, CURRENTSET, 'study', ~isempty(STUDY)+0); + eegh(LASTCOM); + disp('Done'); + eeglab('redraw'); + +elseif ~isempty(LASTCOM) + + % Here the dataset was not modified (plotting only) + EEG = eegh(LASTCOM, EEG); + [ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); + if ~isempty(posEqual) && contains(LASTCOM(1:posEqual(1)), 'EEG') + % dataset modified, store in history + eegh('[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);'); + end + eeglab('redraw'); + % even though EEG is modified by eegh call, do not keep eeg_store in history + % so the history does not reflect modifications to EEG.history for + % better redeability + +end + +clear functionsEEGLAB posEqual; \ No newline at end of file diff --git a/functions/adminfunc/eeglab_options.m b/functions/adminfunc/eeglab_options.m index 297358d3c..9f54a3365 100644 --- a/functions/adminfunc/eeglab_options.m +++ b/functions/adminfunc/eeglab_options.m @@ -1,5 +1,7 @@ -% eeglab_options() - handle EEGLAB options. This script (not function) -% set the various options in the eeg_options() file. +echo off; + +% EEGLAB_OPTIONS - handle EEGLAB options. This script (not function) +% set the various options in the EEG_OPTIONS file. % % Usage: % eeglab_options; @@ -8,43 +10,55 @@ % Copyright (C) Arnaud Delorme, SCCN, INC, UCSD, 2006- % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% 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: % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% 1. Redistributions of source code must retain the above copyright notice, +% this list of conditions and the following disclaimer. % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % load local file % --------------- homefolder = ''; -try, +try %clear eeg_options; % note: we instead clear this function handle in pop_editoptions() - if iseeglabdeployed - com1 = readtxtfile(fullfile(eeglabexefolder, 'eeg_optionsbackup.txt')); - com2 = readtxtfile(fullfile(eeglabexefolder, 'eeg_options.txt')); - eval( com1 ); + eeg_optionsbackup; + if isdeployed || (exist('ismcc') && ismcc) + fileName = which('eeg_options.txt'); + + com2 = readtxtfile(fileName); eval( com2 ); else - eeg_optionsbackup; icadefs; % folder for eeg_options file (also update the pop_editoptions) - if ~isempty(EEGOPTION_PATH) + if ~isempty(EEGOPTION_PATH) % in icadefs above homefolder = EEGOPTION_PATH; elseif ispc - if ~exist('evalc'), eval('evalc = @(x)(eval(x));'); end; - homefolder = deblank(evalc('!echo %USERPROFILE%')); +% if ~exist('evalc'), eval('evalc = @(x)(eval(x));'); end +% homefolder = deblank(evalc('!echo %USERPROFILE%')); + homefolder = getenv('USERPROFILE'); else homefolder = '~'; - end; + end option_file = fullfile(homefolder, 'eeg_options.m'); oldp = pwd; @@ -54,14 +68,18 @@ else tmpp2 = fileparts(which('eeglab_options.m')); cd(tmpp2); - end; - catch, end; + end + catch, end + echo off; eeg_options; % default one with EEGLAB cd(oldp); - end; + end option_savematlab = ~option_savetwofiles; + if option_donotusetoolboxes + disp('Not using signal processing toolbox, if you experience problem, reset your Matlab path to default') + end catch lasterr disp('Warning: could not access the local eeg_options file'); -end; +end diff --git a/functions/adminfunc/eeglab_update.m b/functions/adminfunc/eeglab_update.m new file mode 100644 index 000000000..d30e36563 --- /dev/null +++ b/functions/adminfunc/eeglab_update.m @@ -0,0 +1,387 @@ +% EEGLAB_UPDATE - assess if EEGLAB new updating and ask user to install +% new version +% +% Usage: +% >> eeglab_update +% +% Authors: Arnaud Delorme, SCCN/INC/UCSD, 2019 + +% Copyright (C) 2019 Arnaud Delorme, SCCN/INC/UCSD +% +% 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 eeglab_update(varargin) + +% return at once if users said not to check version +% ------------------------------------------------- +eeglab_options; +if nargin == 0 + [~,eeglabVersionUpdate] = plugin_getweb('update', []); +else + eeglabVersionUpdate = varargin{1}; + if ~option_checkversion && isempty(eeglabVersionUpdate) + return; + end +end + +% Cannot check version for some reason +if isempty(eeglabVersionUpdate) + msg = [ 'Could not check for the latest EEGLAB version (internet may be disconnected).' 10 ... + 'To prevent long startup time, disable checking for new EEGLAB versions (File > Preferences).' ]; + stateWarning = warning('query', 'backtrace'); + warning('off', 'backtrace'); + warning(msg); + warning(stateWarning.state, 'backtrace'); + return +end +if length(eeglabVersionUpdate) > 1 + eeglabVersionUpdate = eeglabVersionUpdate(1); +end + +%% automatic update +eeglabVersionNumber = eeg_getversion; +if isempty(eeglabVersionNumber) + eeglabVersionNumber = 'dev'; +end + +if ~isequal(eeglabVersionUpdate.version, eeglabVersionNumber) && ~isequal(eeglabVersionNumber, 'dev') + stateWarning = warning('query', 'backtrace'); + warning('off', 'backtrace'); + msg = sprintf(['\nA %s revision of EEGLAB (v%s) is available HERE.\n%s\n' ... + 'See Release notes for more information\n' ... + 'You may disable this message in the File > Preferences menu.\n' ], ... + fastif(eeglabVersionUpdate.critical, 'CRITICAL', 'newer'), eeglabVersionUpdate.version, ... + eeglabVersionUpdate.releasenotes, eeglabVersionUpdate.webdoc); + if nargin > 0, warning( msg ); end + warning(stateWarning.state, 'backtrace'); +else + msg = 'You are using the latest version of EEGLAB.'; + if nargin > 0 + fprintf('%s\n', msg); + else + warndlg2(msg); + end + return +end + +% return at once if users said to not show this interface again or no new version available +% ----------------------------------------------------------------------------------------- +eeglab_options; +if nargin > 0 + return +end + +% try saving path +% --------------- +cb_notes = [ 'web(''' eeglabVersionUpdate.webdoc ''', ''-browser'');' ]; +cb_install = 'set(gcbf, ''userdata'', ''install'');'; +cb_custom = 'set(gcbf, ''userdata'', ''custom'');'; +cb_ignore = 'set(gcbf, ''userdata'', ''ignore'');'; +% cb_install = 'set(findobj(gcbf, ''tag'', ''eeglab''), ''userdata'', ''install'');'; +% cb_custom = 'set(findobj(gcbf, ''tag'', ''eeglab''), ''userdata'', ''custom'');'; +% cb_ignore = 'set(findobj(gcbf, ''tag'', ''eeglab''), ''userdata'', ''ignore'');'; +uilist = { ... + { 'style' 'text' 'String' [ 'EEGLAB ' eeglabVersionUpdate.version ' now available' ] 'fontweight' 'bold' } ... + { 'style' 'pushbutton' 'string' 'See release notes' 'callback' cb_notes 'tag' 'eeglab' 'userdata' []} ... + {} ... + {} { 'style' 'pushbutton' 'String' 'Automatic install' 'callback' cb_install } {} ... + {} { 'style' 'pushbutton' 'String' 'Custom install' 'callback' cb_custom } {} ... + {} { 'style' 'pushbutton' 'String' 'Ignore for now' 'callback' cb_ignore } {} ... + {} ... + { 'style' 'text' 'String' [ 'Note: requires 120MB of free space plus the space ' 10 'for copying plugins from the current version' ] } ... + }; +geom = { [1.3 1] [1] [0.5 1 0.5] [0.5 1 0.5] [0.5 1 0.5] [1] [1] }; +geomvert = [ 1 1 1 1 1 1 1.5 ]; +res = supergui( 'geomhoriz', geom, 'geomvert', geomvert, 'uilist', uilist, 'title', 'Update EEGLAB -- eeglab_update()'); +set(gcf, 'userdata', 'wait'); +waitfor( gcf, 'userdata'); +response = get(gcf, 'userdata'); +if iscell(response) % closed figure + return; +end + +% process GUI output +% ------------------ +close(gcf); +if strcmpi(response, 'ignore'), return; end + +% try saving path +% --------------- +try + res = savepath; +catch + res = 1; +end +if res + questdlg2( [ 'EEGLAB cannot modify and save the Matlab path file.' 10 ... + 'Although EEGLAB could still be updated, EEGLAB will not' 10 ... + 'be able to set paths in a way that is persistent after' 10 ... + 'you close Matlab. We therefore recommend that you abort and' 10 ... + 'update EEGLAB manually by downloading the EEGLAB zip file' 10 ... + 'online, uncompress it on your computer and modify and save' 10 ... + 'the Matlab paths manually.' ], 'Install warning message', 'Continue', 'Abord', 'Abord'); +end +clear res; + +% check for duplicate versions of EEGLAB (code copied from eeglab.m) +% -------------------------------------- +eeglabpath = fileparts(mywhich('eeglab.m')); +if nargin < 1 + eeglabpath2 = ''; + if strcmpi(eeglabpath, pwd) || strcmpi(eeglabpath(1:end-1), pwd) + cd('functions'); + warning('off', 'MATLAB:rmpath:DirNotFound'); + rmpath(eeglabpath); + warning('on', 'MATLAB:rmpath:DirNotFound'); + eeglabpath2 = mywhich('eeglab.m'); + cd('..'); + else + try, rmpath(eeglabpath); catch, end + eeglabpath2 = mywhich('eeglab.m'); + end + if ~isempty(eeglabpath2) + eeglabpath2 = eeglabpath2(1:end-length('eeglab.m')); + tmpWarning = warning('backtrace'); + warning backtrace off; + warndlg2( [ 'There are at least two versions of EEGLAB in your path' 10 ... + sprintf('One is at %s', eeglabpath) 10 ... + sprintf('The other one is at %s', eeglabpath2) 10 ... + 'You must at least remove one version from the Matlab path' 10 ... + 'before you can install a new version of EEGLAB. Abording installation.' ] ); + return + end +end + +% force HTTPS +eeglabVersionUpdate.zip = strrep(eeglabVersionUpdate.zip, 'http://', 'https://'); +[~,zipfile,zipext] = fileparts(eeglabVersionUpdate.zip); +zipfile = [ zipfile zipext ]; + +eeglabNewPath = fullfile( fileparts(fileparts(which('eeglab.m'))), [ 'eeglab' eeglabVersionUpdate.version ]); + +if strcmpi(response, 'custom') + cb_folder = 'tmpfolder = uigetdir; if ~isequal(tmpfolder, 0), set(findobj(gcbf, ''tag'', ''folder''), ''string'', tmpfolder); end; clear tmpfolder;'; + cb_path = 'if get(gcbo, ''value'') == 0, warndlg2([ ''This means that you will need to update the paths manually'' ], ''Path warning''); end'; + cbradio = 'set(findobj(gcbf, ''userdata'', ''radio''), ''value'', 0); set(gcbo, ''value'', 1);'; + + uilist = { { 'style' 'text' 'String' 'EEGLAB update interface' 'fontweight' 'bold' } ... + { 'style' 'text' 'String' 'Install folder' } ... + { 'style' 'edit' 'string' eeglabNewPath 'tag' 'folder' 'horizontalalignment' 'right' } ... + { 'style' 'pushbutton' 'string' '...' 'callback' cb_folder } ... + {} ... + { 'style' 'text' 'String' 'What to do with current version main EEGLAB folder?' } ... + {} { 'style' 'popupmenu' 'String' { 'Leave it as is (do nothing)' 'Rename with postfix _old (recommended)' 'Delete it and delete all files it contains' } 'value' 2 'tag' 'popmenuchoice' } ... + {} ... + { 'style' 'text' 'String' 'Other options' } ... + {} { 'style' 'checkbox' 'string' 'Update and resave Matlab paths' 'tag' 'updatepath' 'value' 1 'callback' cb_path } ... + {} { 'style' 'checkbox' 'string' 'Copy current EEGLAB version plugins' 'value' 1 'tag' 'copyplugins' } ... + {} { 'style' 'checkbox' 'string' 'Copy EEGLAB preferences' 'value' 1 'tag' 'copyprefs' } ... + }; + + geom = { [1] [1 2 0.4] [1] [1] [0.1 1] [1] [1] [0.1 1] [0.1 1] [0.1 1] }; + geomvert = [ 1 1 0.5 1 1 0.5 1 1 1 1 ]; + [ res2, ~, ~, res] = inputgui( 'geometry', geom, 'geomvert', geomvert, 'uilist', uilist, ... + 'helpcom', 'pophelp(''eeglab_update'')', 'title', 'Update EEGLAB -- eeglab_update()'); + if isempty(res2), return; end + res.oldnothing = false; + res.oldmove = false; + res.olddelete = false; + switch res.popmenuchoice + case 1, res.oldnothing = true; + case 2, res.oldmove = true; + case 3, res.olddelete = true; + end +else + res.folder = eeglabNewPath; + res.oldnothing = false; + res.oldmove = true; + res.olddelete = false; + res.updatepath = true; + res.copyplugins = true; + res.copyprefs = true; +end +[parentPath,eeglabFolder,ext] = fileparts(res.folder); +eeglabFolder = [ eeglabFolder ext ]; + +% check if target folder can be written into +% ----------------------------------------- +if ~exist(res.folder) + try + createDir = mkdir(res.folder); + catch + createDir = 0; + end + if ~createDir + msg = [ 'Parent folder of EEGLAB folder is not writable, select another location. Operation aborded.' ]; + warndlg2(msg); + return; + end +else + msg = [ 'EEGLAB target folder already exist ' res.folder 10 'Remove it manually or select another folder for installing EEGLAB.' ]; + warndlg2(msg); + return; +end + +% start downloading EEGLAB +% ------------------------ +try + restmp = questdlg2('This will download about 80Mb with no wait bar, be patient.', 'Warning', 'Cancel', 'OK', 'OK'); + if isempty(restmp) || strcmpi(restmp, 'Cancel'), return; end + disp('Downloading about 80Mb, hang in there...'); + plugin_urlwrite( eeglabVersionUpdate.zip, fullfile(parentPath, zipfile)); +catch + msg = [ 'Could not download EEGLAB. Server might be unavailable, or your internet might' 10 ... + 'be down or too slow. Alternatively, your version of Matlab might not support HTTPS.' 10 ... + 'Try again just in case. Otherwise, download the new zip file from the Internet.' ]; + warndlg2(msg); + return; +end + +% unzip EEGLAB +% ------------ +disp([ 'Unzipping EEGLAB... ']); +unzip(fullfile(parentPath, zipfile), fullfile(parentPath, eeglabFolder)); + +disp('Cleaning EEGLAB zip file...'); +delete(fullfile(parentPath, zipfile)); + +% seeing what is in the plugin folder and moving files if necessary +% ---------------------------------------------------------- +eeglabContent = dir(fullfile(parentPath, eeglabFolder)); +if length(eeglabContent) < 5 + for index = 1:length(eeglabContent) + if ~strcmpi(eeglabContent(index).name, '.') && ~strcmpi(eeglabContent(index).name, '..') + fullFolder = fullfile(parentPath, eeglabFolder, eeglabContent(index).name); + if exist(fullFolder) == 7 % folder detected + % move files from folder + movefile(fullfile(fullFolder, '*'), fullfile(parentPath, eeglabFolder)); + rmdir(fullFolder, 's'); + end + end + end + fprintf('EEGLAB is now installed\n'); +end + +% copying eeg_options but only if the one being used is in the EEGLAB current folder +% ---------------------------------------------------------------------------------- +if res.copyprefs + eeglab_options; + if length(option_file) > length(eeglabpath) && strcmpi(eeglabpath, option_file(1:length(eeglabpath))) + copyfile(option_file, fullfile(parentPath, eeglabFolder, 'functions', 'adminfunc', 'eeg_options.m')); + end +end + +% update the paths +% ---------------- +if res.updatepath + p = path; + if ispc + p = textscan(p, '%s', 'delimiter', ';'); + else + p = textscan(p, '%s', 'delimiter', ':'); + end + p = p{1}; + rmInd = []; + for iPath = 1:length(p) + if length(p{iPath}) >= length(eeglabpath) && strcmpi(eeglabpath, p{iPath}(1:length(eeglabpath))) + rmInd = [ rmInd iPath ]; + end + end + p(rmInd) = []; + p(:,2) = { ';' }; + p = p'; + p = strcat(p{:}); + path(p); + addpath(fullfile(parentPath, eeglabFolder)); + savepath; + disp('Paths updated and saved successfully...'); +end + +% copying plugins +% --------------- +disp('EEGLAB require some plugins to function properly.'); +disp('Updated versions of plugins Dipfit, Firfilt, ICLabel, and clean_rawdata are automatically included'); +if res.copyplugins + pluginOri = fullfile(eeglabpath, 'plugins'); + pluginDest = fullfile(parentPath, eeglabFolder, 'plugins'); + + pluginOriList = dir(pluginOri); + for iPlugin = 1:length(pluginOriList) + if ~isequal(pluginOriList(iPlugin).name, '.') && ... + ~isequal(pluginOriList(iPlugin).name, '..') && ... + isempty(strfind(lower(pluginOriList(iPlugin).name), 'dipfit')) && ... + isempty(strfind(lower(pluginOriList(iPlugin).name), 'firfilt')) && ... + isempty(strfind(lower(pluginOriList(iPlugin).name), 'iclabel')) && ... + isempty(strfind(lower(pluginOriList(iPlugin).name), 'clean_rawdata')) + destPath = fullfile(pluginDest, pluginOriList(iPlugin).name); + try + mkdir(destPath); + copyfile(fullfile( pluginOri, pluginOriList(iPlugin).name, '*'), destPath); + fprintf('Plugin %s copied successfully\n', pluginOriList(iPlugin).name); + catch + fprintf('Issue with copying plugin %s - we suggest you reinstall it from the plugin manager\n', pluginOriList(iPlugin).name); + end + end + end +end + +% renaming old EEGLAB folder +% -------------------------- +cd(fullfile(parentPath, eeglabFolder)); +if res.oldmove + try + moveRes = movefile(eeglabpath, [ eeglabpath '_old' ]); + catch + moveRes = 0; + end + if ~moveRes + disp('Could not rename the old EEGLAB folder. Make sure you have permission to do so.'); + disp('This does not affect EEGLAB installation which is now complete.'); + else + disp('Old EEGLAB folder renamed successfully...'); + end +end +if res.olddelete + try + delRes = rmdir(eeglabpath, 's'); + catch + delRes = 0; + end + if ~delRes + disp('Could not delete the old EEGLAB folder. Make sure you have permission to do so.'); + disp('This does not affect EEGLAB installation which is now complete.'); + else + disp('Old EEGLAB folder deleted successfully...'); + end +end +evalin('base', 'eeglab'); + +function res = mywhich(varargin); +try + res = which(varargin{:}); +catch + fprintf('Warning: permission error accessing %s\n', varargin{1}); +end diff --git a/functions/adminfunc/eeglabexefolder.m b/functions/adminfunc/eeglabexefolder.m deleted file mode 100644 index 54a0e4433..000000000 --- a/functions/adminfunc/eeglabexefolder.m +++ /dev/null @@ -1,26 +0,0 @@ -% eeglabexefolder - return the exe folder for EEGLAB. This function is only -% relevant for the compiled version of EEGLAB. -% -% Author: Arnaud Delorme, SCCN & CERCO, CNRS, 2008- - -% Copyright (C) 15 Feb 2002 Arnaud Delorme, Salk Institute, arno@salk.edu -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -function str = eeglabexefolder; - -str = ctfroot; -inds = find(str == filesep); -str = str(1:inds(end)-1); diff --git a/functions/adminfunc/gethelpvar.m b/functions/adminfunc/gethelpvar.m index a42183d04..f3bb1cf34 100644 --- a/functions/adminfunc/gethelpvar.m +++ b/functions/adminfunc/gethelpvar.m @@ -1,4 +1,4 @@ -% gethelpvar() - convert a Matlab m-file help-message header +% GETHELPVAR - convert a Matlab m-file help-message header % into out variables % Usage: % >> [vartext, varnames] = gethelpvar( filein, varlist); @@ -6,49 +6,60 @@ % Inputs: % filein - input filename (with .m extension) % varlist - optional list of variable to return. If absent -% retrun all variables. +% return all variables. % % Outputs: % vartext - variable text -% varnames - name of the varialbe returned; +% varnames - name of the variable returned; % -% Notes: see help2html() for file format +% Notes: see HELP2HTML for file format % % Example: >> gethelpvar( 'gethelpvar.m', 'filein') % % Author: Arnaud Delorme, Salk Institute 20 April 2002 % -% See also: help2html() +% See also: HELP2HTML % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [alltext, allvars] = gethelpvar( filename, varlist ) if nargin < 1 help gethelpvar; return; -end; +end % input file % ---------- fid = fopen( filename, 'r'); if fid == -1 error('File not found'); -end; +end cont = 1; % scan file @@ -86,9 +97,9 @@ switch lower(str(1:i2d)) case { 'usage:' 'authors:' 'author:' 'notes:' 'note:' 'input:' ... 'inputs:' 'outputs:' 'output' 'example:' 'examples:' 'see also:' }, newtitle = 1; - end; - if (i2d == length(str)) & (str(1) ~= '%'), newtitle = 1; end; - end; + end + if (i2d == length(str)) && (str(1) ~= '%'), newtitle = 1; end; + end if newtitle tilehtml = str(1:i2d); newtitle = 1; @@ -107,7 +118,7 @@ [tok1 strrm] = strtok( str ); [tok2 strrm] = strtok( strrm ); - if ~isempty(tok2) & ( isequal(tok2,'-') | isequal(tok2,'=')) % new variable + if ~isempty(tok2) && ( isequal(tok2,'-') || isequal(tok2,'=')) % new variable newvar = 1; oldvarname = varname; oldvartext = vartext; @@ -127,18 +138,18 @@ vartext = str; else if ~isempty(varname) - vartext = [ vartext 10 str]; % espace if in array + vartext = [ vartext 10 str]; % space if in array else - if length(vartext)>3 & all(vartext( end-2:end) == '.') - vartext = [ deblank2(vartext(1:end-3)) 10 str]; % espace if '...' + if length(vartext)>3 && all(vartext( end-2:end) == '.') + vartext = [ deblank2(vartext(1:end-3)) 10 str]; % space if '...' else vartext = [ vartext 10 str]; % CR otherwise end; end; - end; + end end; newtitle = 0; - end; + end % --- END OF DECODING str = fgets( fid ); @@ -156,7 +167,7 @@ else if ~isempty(oldvartext) %fprintf( fo, [ g.normcol2 g.tabtext '\n' ], oldvartext); - end; + end end; newvar = 1; oldvarname = varname; @@ -166,7 +177,7 @@ % test if new input for an array % ------------------------------ - if newvar | newtitle + if newvar || newtitle if maindescription if ~isempty(oldvartext) % FUNCTION TITLE maintext = oldvartext; @@ -181,7 +192,7 @@ %fprintf(fo, [ g.normrow g.doublecol ... % '

' ]); - %end; + %end end; elseif ~isempty(oldvarname) allvars{indexout} = oldvarname; @@ -192,7 +203,7 @@ else if ~isempty(oldvartext) %fprintf( fo, [ g.normcol2 g.text '\n' ], oldvartext); - end; + end end; end; @@ -205,21 +216,21 @@ end; oldvarname = []; oldvartext = []; - end; + end else str = fgets( fid ); - end; -end; + end +end fclose( fid ); % remove quotes of variables % -------------------------- for index = 1:length(allvars) - if allvars{index}(1) == '''', allvars{index} = eval( allvars{index} ); end; -end; + if allvars{index}(1) == '''', allvars{index} = eval( allvars{index} ); end +end if exist('varlist') == 1 - if ~iscell(varlist), varlist = { varlist }; end; + if ~iscell(varlist), varlist = { varlist }; end newtxt = mat2cell(zeros(length(varlist), 1), length(varlist), 1); % preallocation for index = 1:length(varlist) loc = strmatch( varlist{index}, allvars); @@ -228,10 +239,10 @@ else disp([ 'warning: variable ''' varlist{index} ''' not found']); newtxt{index} = ''; - end; - end; + end + end alltext = newtxt; -end; +end return; @@ -254,21 +265,21 @@ strout = [strout ' ' tokout ]; end; [tok1 strrm] = strtok( strrm ); - end; + end return; function tokout = functionformat( tokin, refcall ); tokout = tokin; % default [test, realtokin, tail] = testfunc1( tokin ); - if ~test, [test, realtokin, tail] = testfunc2( tokin ); end; + if ~test, [test, realtokin, tail] = testfunc2( tokin ); end if test i1 = findstr( refcall, '%s'); i2 = findstr( refcall(i1(1):end), ''''); - if isempty(i2) i2 = length( refcall(i1(1):end) )+1; end; + if isempty(i2) i2 = length( refcall(i1(1):end) )+1; end filename = [ realtokin refcall(i1+2:i1+i2-2)]; if exist( filename ) % do not make link if the file does not exist tokout = sprintf( [ '%s' tail ' ' ], realtokin, realtokin ); - end; + end end; return; @@ -276,9 +287,9 @@ test = 0; realtokin = ''; tail = ''; if ~isempty( findstr( tokin, '()' ) ) realtokin = tokin( 1:findstr( tokin, '()' )-1); - if length(realtokin) < (length(tokin)-2) tail = tokin(end); else tail = []; end; + if length(realtokin) < (length(tokin)-2) tail = tokin(end); else tail = []; end test = 1; - end; + end return; function [test, realtokin, tail] = testfunc2( tokin ) % test if is string is 'FUNCTION[,]' @@ -289,13 +300,13 @@ tail = ','; else realtokin = tokin; - end; + end testokin = realtokin; testokin(findstr(testokin, '_')) = 'A'; testokin(findstr(testokin, '2')) = 'A'; - if all(double(testokin) > 64) & all(double(testokin) < 91) + if all(double(testokin) > 64) && all(double(testokin) < 91) test = 1; end; realtokin = lower(realtokin); - end; + end return; diff --git a/functions/adminfunc/getkeyval.m b/functions/adminfunc/getkeyval.m index 16ee357f9..31e7b18f8 100644 --- a/functions/adminfunc/getkeyval.m +++ b/functions/adminfunc/getkeyval.m @@ -1,4 +1,4 @@ -% getkeyval() - get variable value from a 'key', 'val' sequence string. +% GETKEYVAL - get variable value from a 'key', 'val' sequence string. % % Usage: % >> val = getkeyval( keyvalstr, varname, mode, defaultval); @@ -11,8 +11,8 @@ % mode - if the value extracted is an integer array, the % 'mode' variable can contain a subset of indexes to return. % If mode is 'present', then either 0 or 1 is returned -% depending on wether the variable is present. -% defaultval - default value if the varible is not found +% depending on whether the variable is present. +% defaultval - default value if the variable is not found % % Outputs: % val - a value for the variable @@ -22,46 +22,57 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, 29 July 2002 % -% See also: gethelpvar() +% See also: GETHELPVAR % Copyright (C) 2002 arno@salk.edu, Arnaud Delorme, CNL / Salk Institute % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 txt = getkeyval(lastcom, var, mode, default) % mode can be present for 0 and 1 if the variable is present if nargin < 1 help getkeyval; return; - end; + end if nargin < 4 default = ''; - end; + end if isempty(lastcom) txt = default; return; - end; + end if nargin < 3 mode = ''; - end; - if isstr(mode) & strcmp(mode, 'present') + end + if ischar(mode) && strcmp(mode, 'present') if ~isempty(findstr(var, lastcom)) txt = 1; return; else txt = 0; return; - end; - end; + end + end if isnumeric(var) comas = findstr(lastcom, ','); if length(comas) >= var @@ -69,26 +80,26 @@ tmpval = eval( txt ); if isempty(tmpval), txt = ''; else txt = vararg2str( tmpval ); - end; + end return; % txt = deblank(txt(end:-1:1)); % txt = deblank(txt(end:-1:1)); % -% if ~isempty(txt) & txt(end) == '}', txt = txt(2:end-1); end; +% if ~isempty(txt) & txt(end) == '}', txt = txt(2:end-1); end % if ~isempty(txt) % txt = deblank(txt(end:-1:1)); % txt = deblank(txt(end:-1:1)); -% end; -% if ~isempty(txt) & txt(end) == ']', txt = txt(2:end-1); end; +% end +% if ~isempty(txt) & txt(end) == ']', txt = txt(2:end-1); end % if ~isempty(txt) % txt = deblank(txt(end:-1:1)); % txt = deblank(txt(end:-1:1)); -% end; -% if ~isempty(txt) & txt(end) == '''', txt = txt(2:end-1); end; +% end +% if ~isempty(txt) & txt(end) == '''', txt = txt(2:end-1); end else txt = default; - end; + end %fprintf('%s:%s\n', var, txt); return; else @@ -106,7 +117,7 @@ if ~isempty(parent) comas = comas(find(comas >parent(1))); txt = lastcom(comas(1)+1:comas(2)-1); - end; + end txt = [ '''' var ''', ' txt ]; elseif isnumeric(mode) txt = str2num(txt); @@ -118,18 +129,18 @@ elseif length(txt) >= mode(1) if all(isnan(txt(mode(1)))), txt = ''; else txt = num2str(txt(mode(1))); - end; + end else txt = default; - end; + end else txt = num2str(txt); - end; + end elseif txt(1) == '''' txt = txt(2:end-1); % remove quotes for text - end; + end else txt = default; - end; - end; + end + end %fprintf('%s:%s\n', var, txt); diff --git a/functions/adminfunc/gettext.m b/functions/adminfunc/gettext.m index 16ea0758d..e8284896d 100644 --- a/functions/adminfunc/gettext.m +++ b/functions/adminfunc/gettext.m @@ -1,4 +1,4 @@ -% gettext() - This function prints a dialog box on screen and waits for +% GETTEXT - This function prints a dialog box on screen and waits for % the user to enter a string. There is a cancel button which % returns a value of []. % Usage: @@ -8,19 +8,30 @@ % Copyright (C) 1997 Colin Humphries, Salk Institute % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license -ad diff --git a/functions/adminfunc/hlp_argstruct2linearcell.m b/functions/adminfunc/hlp_argstruct2linearcell.m index 353eeafcb..b7af12212 100644 --- a/functions/adminfunc/hlp_argstruct2linearcell.m +++ b/functions/adminfunc/hlp_argstruct2linearcell.m @@ -1,4 +1,4 @@ -% hlp_argstruct2linearcell() - Linearize configation output of arg_guipanel +% HLP_ARGSTRUCT2LINEARCELL - Linearize configation output of arg_guipanel % % Usage: % >> cellval = hlp_argstruct2linearcells( cfg ); @@ -13,19 +13,30 @@ % Copyright (C) 2013 Arnaud Delorme % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 cellval = hlp_argstruct2linearcell(cfg); @@ -45,12 +56,12 @@ cellval = { cellval{:} ff{iField} vararg2str(val) }; else cellval = { cellval{:} ff{iField} val }; - end; - end; - end; + end + end + end end else cellval = cfg; - end; + end diff --git a/functions/adminfunc/intersect_bc.m b/functions/adminfunc/intersect_bc.m index 1a2a39934..b9b4cdbfd 100644 --- a/functions/adminfunc/intersect_bc.m +++ b/functions/adminfunc/intersect_bc.m @@ -1,20 +1,47 @@ % intersect_bc - intersect backward compatible with Matlab versions prior to 2013a -function [C,IA,IB] = intersect_bc(A,B,varargin); +% Copyright (C) 2013 Arnaud Delorme +% +% 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 [C,IA,IB] = intersect_bc(A,B,varargin) errorFlag = error_bc; v = version; indp = find(v == '.'); v = str2num(v(1:indp(2)-1)); -if v > 7.19, v = floor(v) + rem(v,1)/10; end; +if v > 7.19, v = floor(v) + rem(v,1)/10; end if nargin > 2 ind = strmatch('legacy', varargin); if ~isempty(ind) varargin(ind) = []; - end; -end; + end +end if v >= 7.14 [C,IA,IB] = intersect(A,B,varargin{:},'legacy'); @@ -22,8 +49,8 @@ [C2,IA2,IB2] = intersect(A,B,varargin{:}); if (~isequal(C, C2) || ~isequal(IA, IA2) || ~isequal(IB, IB2)) warning('backward compatibility issue with call to intersect function'); - end; - end; + end + end else [C,IA,IB] = intersect(A,B,varargin{:}); -end; \ No newline at end of file +end diff --git a/functions/adminfunc/is_sccn.m b/functions/adminfunc/is_sccn.m index e6e6b9885..02205fa64 100644 --- a/functions/adminfunc/is_sccn.m +++ b/functions/adminfunc/is_sccn.m @@ -1,14 +1,14 @@ -% is_sccn() - returns 1 if computer is located at SCCN (Swartz Center +function bool = is_sccn +% IS_SCCN - returns 1 if computer is located at SCCN (Swartz Center % for computational Neuroscience) and 0 otherwise -function bool = is_sccn; - - bool = 0; - domnane = ' '; - try - eval([ 'if isunix, [tmp domname] = unix(''hostname -d'');' ... - 'end;' ... - 'bool = strcmpi(domname(1:end-1), ''ucsd.edu'');' ], ''); - catch, - end; - +bool = 0; +domnane = ' '; +try + eval([ 'if isunix, [tmp domname] = unix(''hostname'');' ... + 'end;' ... + 'bool = findstr(domname(1:end-1), ''ucsd.edu'');' ... + 'if isempty(bool), bool=0; else bool=1; end;' ], ''); +catch +end + diff --git a/functions/adminfunc/iseeglabdeployed.m b/functions/adminfunc/iseeglabdeployed.m index 5ec7b36ac..765bd7f0a 100644 --- a/functions/adminfunc/iseeglabdeployed.m +++ b/functions/adminfunc/iseeglabdeployed.m @@ -1,7 +1,7 @@ -% iseeglabdeployed - true for EEGLAB compile version and false otherwise function val = iseeglabdeployed +% iseeglabdeployed - true for EEGLAB compile version and false otherwise try val = isdeployed; catch val = 0; -end \ No newline at end of file +end diff --git a/functions/adminfunc/ismatlab.m b/functions/adminfunc/ismatlab.m index 3773b6bc0..53da57a09 100644 --- a/functions/adminfunc/ismatlab.m +++ b/functions/adminfunc/ismatlab.m @@ -1,8 +1,3 @@ -function res = ismatlab; - -v = version; -if v(1) > '4' - res = 1; -else - res = 0; -end; \ No newline at end of file +function res = ismatlab +% true if called from Matlab; false if called from Octave +res = exist('OCTAVE_VERSION','builtin') == 0; diff --git a/functions/adminfunc/ismember_bc.m b/functions/adminfunc/ismember_bc.m index a6b535872..6a6fff289 100644 --- a/functions/adminfunc/ismember_bc.m +++ b/functions/adminfunc/ismember_bc.m @@ -1,20 +1,47 @@ % ismember_bc - ismember backward compatible with Matlab versions prior to 2013a -function [C,IA] = ismember_bc(A,B,varargin); +% Copyright (C) 2013 Arnaud Delorme +% +% 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 [C,IA] = ismember_bc(A,B,varargin) errorFlag = error_bc; v = version; indp = find(v == '.'); v = str2num(v(1:indp(2)-1)); -if v > 7.19, v = floor(v) + rem(v,1)/10; end; +if v > 7.19, v = floor(v) + rem(v,1)/10; end if nargin > 2 ind = strmatch('legacy', varargin); if ~isempty(ind) varargin(ind) = []; - end; -end; + end +end if v >= 7.14 [C,IA] = ismember(A,B,varargin{:},'legacy'); @@ -22,8 +49,8 @@ [C2,IA2] = ismember(A,B,varargin{:}); if (~isequal(C, C2) || ~isequal(IA, IA2)) warning('backward compatibility issue with call to ismember function'); - end; - end; + end + end else [C,IA] = ismember(A,B,varargin{:}); -end; \ No newline at end of file +end diff --git a/functions/adminfunc/plugin_askinstall.m b/functions/adminfunc/plugin_askinstall.m index aca395c10..ca87f245e 100644 --- a/functions/adminfunc/plugin_askinstall.m +++ b/functions/adminfunc/plugin_askinstall.m @@ -1,51 +1,95 @@ +% PLUGIN_ASKINSTALL - install EEGLAB plugin from a GUI or command line +% call. +% Usage: +% plugin_askinstall(pluginName, pluginFunc, force); +% +% Inputs: +% pluginName - [string] name of the plugin +% pluginFunc - [string] function belonging to the plugin +% force - [boolean] force install (even if already installed) +% +% Example: +% Force install BVA-IO +% plugin_askinstall('bva-io', [], true); + +% Copyright (C) 2012- Arnaud Delorme +% +% 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 installRes = plugin_askinstall(pluginName, pluginFunc, forceInstall) -if nargin < 3, forceInstall = false; end; +if nargin < 3, forceInstall = false; end -if nargin < 2 || ~exist(pluginFunc) +if nargin < 2 || ~exist(char(pluginFunc)) if ~forceInstall db = dbstack; - if length(db) > 2 && ~strcmpi(db(end).name, 'checkouteeglab.m'); + if length(db) > 2 && ~strcmpi(db(end).file, 'checkouteeglab.m') error([ 'Cannot find ' pluginName ' extension, use EEGLAB Extension Manager to install it' ]); - end; + end installRes = 0; % check is deactivated - try, PLUGINLIST = evalin('base', 'PLUGINLIST'); catch, PLUGINLIST = []; end; + try, PLUGINLIST = evalin('base', 'PLUGINLIST'); catch, PLUGINLIST = []; end if ~isempty(PLUGINLIST) && isfield(PLUGINLIST, 'plugin') indPlugin = strmatch(lower(pluginName), lower({ PLUGINLIST.plugin }), 'exact'); if ~isempty(indPlugin) && strcmpi(PLUGINLIST(indPlugin(1)).status, 'deactivated') res = questdlg2( [ pluginName ' extension is de-activated. Do you want to reactivate it now?' ], [ pluginName ' extension installation' ], 'No', 'Yes', 'Yes' ); - if strcmpi(res, 'no'), return, end; + if strcmpi(res, 'no'), return, end plugin_reactivate(PLUGINLIST(indPlugin(1)).foldername); evalin('base', 'eeglab rebuild'); installRes = 1; return; - end; - end; + end + end % check for installing res = questdlg2( [ pluginName ' extension is not installed. Do you want to download it now?' ], [ pluginName ' extension installation' ], 'No', 'Yes', 'Yes' ); else res = 'yes'; - end; + end - if strcmpi(res, 'no'), return, end; - plugins = plugin_getweb('import', []); + if strcmpi(res, 'no'), return, end + try + plugins = plugin_getweb('plugin_install', []); + catch + error('Issue with retrieving statistics for extensions, maybe check your connection'); + end + if isempty(plugins) + error('Cannot download the extension. Please check your internet connection'); + end indPlugin = strmatch(lower(pluginName), lower({ plugins.name }), 'exact'); - if isempty(indPlugin), - plugins = plugin_getweb('process', []); - indPlugin = strmatch(lower(pluginName), lower({ plugins.name })); - if isempty(indPlugin), - error([ pluginName ' extension not found' ]); - end; - end; + if isempty(indPlugin) + error([ pluginName ' extension not found' ]); + end result = plugin_install(plugins(indPlugin(1)).zip, plugins(indPlugin(1)).name, plugins(indPlugin(1)).version, forceInstall); - if result == 1, installRes = 1; end; + if result == 1, installRes = 1; end evalin('base', 'eeglab rebuild'); else installRes = 1; -end; +end diff --git a/functions/adminfunc/plugin_convert.m b/functions/adminfunc/plugin_convert.m deleted file mode 100644 index aa3084ae9..000000000 --- a/functions/adminfunc/plugin_convert.m +++ /dev/null @@ -1,9 +0,0 @@ -function plugin = plugin_convert(pluginOri) - -for iRow = 1:length(pluginOri) - plugin(iRow).currentversion = pluginOri(iRow).version; - plugin(iRow).foldername = pluginOri(iRow).foldername; - plugin(iRow).status = pluginOri(iRow).status; - plugin(iRow).name = pluginOri(iRow).plugin; - plugin(iRow).installed = 1; -end; \ No newline at end of file diff --git a/functions/adminfunc/plugin_deactivate.m b/functions/adminfunc/plugin_deactivate.m deleted file mode 100644 index 7e1afbb00..000000000 --- a/functions/adminfunc/plugin_deactivate.m +++ /dev/null @@ -1,28 +0,0 @@ -function plugin_deactivate(foldername); - - % get plugin path - % --------------- - fullpluginfolder = fullfile(fileparts(which('eeglab.m')), 'plugins', foldername); - if ~exist(fullpluginfolder) - error([ 'Could not find folder ' foldername 'in extension folder' ]); - end; - - disp('Removing extension from path'); - allPaths = path; - indSep = [0 find(allPaths == ':') length(allPaths)+1]; - for index = 1:length(indSep)-1 - tmpPath = allPaths(indSep(index)+1:indSep(index+1)-1); - if ~isempty(strfind(tmpPath, fullpluginfolder)) - rmpath(tmpPath); - fprintf('Removing path %s\n', tmpPath); - end; - end; - - disp([ 'Moving extension ' foldername ' to deactivatedplugins folder' ]); - fulldeactivatedpluginfolder = fullfile(fileparts(which('eeglab.m')), 'deactivatedplugins'); - if ~exist(fulldeactivatedpluginfolder), mkdir(fulldeactivatedpluginfolder); end; - try - movefile(fullpluginfolder, fulldeactivatedpluginfolder); - catch - eeglab_error; - end; \ No newline at end of file diff --git a/functions/adminfunc/plugin_extract.m b/functions/adminfunc/plugin_extract.m index b1de0a1c1..cb78cce9b 100644 --- a/functions/adminfunc/plugin_extract.m +++ b/functions/adminfunc/plugin_extract.m @@ -1,280 +1,33 @@ -function restartEeglabFlag = plugin_extract(type, pluginlist, page) - -if nargin < 3, page = 1; end; -% type may be 'import' or 'process' -restartEeglabFlag = false; -pluginsPerPage = 15; - -% check the presence of unzip -%str = evalc('!unzip'); -%if length(str) < 200 -% error([ '"unzip" could not be found. Instal unzip and make sure' 10 'it is accessible under Matlab by adding the program to' 10 'the path and typing "!unzip"' ]); -%end; - -if ~isstruct(type) - plugin = plugin_getweb(type, pluginlist, 'newlist'); - % sort plugins by download score - [tmp scoreOrder] = sort([ plugin.downloads ], 2, 'descend'); - plugin = plugin(scoreOrder); -else - plugin = type; -end; - -% select page -allPlugins = plugin; -numPlugin = length(plugin); -moreThanOnePage = 0; -if numPlugin > pluginsPerPage - plugin = plugin(pluginsPerPage*(page-1)+1:min(length(plugin),pluginsPerPage*page)); - moreThanOnePage = 1; -end; - -% find which menu to show -newInstallFlag = false; -installedFlag = false; -deactivatedFlag = false; -for iPlugin = length(plugin):-1:1 - if ~plugin(iPlugin).installed, newInstallFlag = true; end; - if plugin(iPlugin).installed && ~strcmpi(plugin(iPlugin).status, 'deactivated'), installedFlag = true; end; - if strcmpi(plugin(iPlugin).status, 'deactivated'), deactivatedFlag = true; end; -end; - -uilist = {}; -geom = {}; -geomvert = []; -pluginIndices = []; -callback = [ 'tmptag = get(gcbo, ''tag'');' ... - 'if tmptag(3) == ''1'', tmptag(3) = ''2''; else tmptag(3) = ''1''; end;' ... - 'if get(gcbo, ''value''), set(findobj(gcbf, ''tag'', tmptag), ''value'', 0); end; clear tmptag;' ]; +% deprecated function to install plugin - use plugin_menu instead + +% Copyright (C) 2012- Arnaud Delorme +% +% 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. -% ------------------ -% plugins to install -% ------------------ -maxchar = 60; -geom = {}; -lineGeom = [ 0.28 0.28 0.95 0.6 0.6 3 0.35 ]; -if newInstallFlag - uilist = { {} { 'style' 'text' 'string' 'Extensions available for install on the internet' 'fontweight' 'bold' 'fontsize' 18 'tag' 'title' } }; - uilist = { uilist{:} { 'style' 'text' 'string' 'I' 'tag' 'install' } { } ... - { 'style' 'text' 'string' 'Plugin' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Vers.' 'tag' 'verweb' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Score' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Description' 'fontweight' 'bold' } {}}; - geom = { [1 5.5] lineGeom }; - geomvert = [1 1]; - for iRow = 1:length(plugin) - if ~plugin(iRow).installed && ~strcmpi(plugin(iRow).status, 'deactivated') - % text for description - description = plugin(iRow).description; - if length(description) > maxchar+2 - description = [ description(1:min(maxchar,length(description))) '...' ]; - end; - - enableWebDoc = fastif(isempty(plugin(iRow).webdoc), 'off', 'on'); - - userdata = ''; - if plugin(iRow).installed && plugin(iRow).installorupdate, userdata = 'colortored'; end; - uilist = { uilist{:}, ... - { 'style' 'checkbox' 'string' '' 'value' 0 'enable' 'on' }, ... - { 'style' 'checkbox' 'string' '' 'visible' 'off' }, ... - { 'style' 'text' 'string' plugin(iRow).name }, ... - { 'style' 'text' 'string' plugin(iRow).version 'tag' 'latestversion' 'userdata' userdata }, ... - { 'style' 'text' 'string' int2str(plugin(iRow).downloads) }, ... - { 'style' 'text' 'string' description }, ... - { 'style' 'pushbutton' 'string' 'Doc' 'enable' enableWebDoc 'callback' myweb(plugin(iRow).webdoc) } }; - geom = { geom{:}, lineGeom }; - geomvert = [ geomvert 1]; - pluginIndices = [ pluginIndices iRow ]; - end; - end; -end; - -% ----------------- -% installed plugins -% ----------------- -if installedFlag - uilist = { uilist{:} {} {} { 'style' 'text' 'string' 'Installed extensions' 'fontweight' 'bold' 'fontsize' 18 'tag' 'title' } }; - uilist = { uilist{:} { 'style' 'text' 'string' 'I' 'tag' 'update' } ... - { 'style' 'text' 'string' 'I' 'tag' 'deactivate' } ... - { 'style' 'text' 'string' 'Plugin' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Vers.' 'tag' 'verweb' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Score' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Description' 'fontweight' 'bold' } {}}; - - geom = { geom{:} 1 [1 5.5] lineGeom }; - geomvert = [geomvert 1 1 1]; - for iRow = 1:length(plugin) - if plugin(iRow).installed && ~strcmpi(plugin(iRow).status, 'deactivated') - % text for description - description = plugin(iRow).description; - if length(description) > maxchar+2 - description = [ description(1:min(maxchar,length(description))) '...' ]; - end; - - enableWebDoc = fastif(isempty(plugin(iRow).webdoc), 'off', 'on'); - - userdata = ''; - if plugin(iRow).installorupdate, - textnew = [ 'Click update to install version ' plugin(iRow).version ' now available on the web' ]; - userdata = 'colortored'; - else - textnew = description; - end; - uilist = { uilist{:}, ... - { 'style' 'checkbox' 'string' '' 'value' 0 'enable' fastif(plugin(iRow).installorupdate, 'on', 'off') 'tag' [ 'cb1' int2str(iRow) ] 'callback' callback }, ... - { 'style' 'checkbox' 'string' '' 'enable' 'on' 'tag' [ 'cb2' int2str(iRow) ] 'callback' callback }, ... - { 'style' 'text' 'string' plugin(iRow).name }, ... - { 'style' 'text' 'string' plugin(iRow).currentversion 'tag' 'latestversion'}, ... - { 'style' 'text' 'string' int2str(plugin(iRow).downloads) }, ... - { 'style' 'text' 'string' textnew 'userdata' userdata }, ... - { 'style' 'pushbutton' 'string' 'Doc' 'enable' enableWebDoc 'callback' myweb(plugin(iRow).webdoc) } }; - geom = { geom{:}, lineGeom }; - geomvert = [ geomvert 1]; - pluginIndices = [ pluginIndices iRow ]; - end; - end; -end; - -% ------------------- -% deactivated plugins -% ------------------- -%geom = { geom{:} 1 1 }; -%geomvert = [geomvert 0.5 1]; -%uilist = { uilist{:} {} { 'style' 'text' 'string' 'To manage deactivated plugins, use menu item File > Manage plugins > Manage deactivated plugins' } }; -if deactivatedFlag - uilist = { uilist{:} {} {} { 'style' 'text' 'string' 'List of deactivated extensions ' 'fontweight' 'bold' 'fontsize' 18 'tag' 'title' } }; - uilist = { uilist{:} ... - { 'style' 'text' 'string' 'I' 'tag' 'reactivate' } ... - { 'style' 'text' 'string' 'I' 'tag' 'remove1' } ... - { 'style' 'text' 'string' 'Plugin' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Vers.' 'tag' 'verweb' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Score' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Description' 'fontweight' 'bold' } {}}; - geom = { geom{:} 1 [1 5.5] lineGeom }; - geomvert = [geomvert 1 1 1]; - for iRow = 1:length(plugin) - if strcmpi(plugin(iRow).status, 'deactivated') - % text for description - description = plugin(iRow).description; - if length(description) > maxchar+2 - description = [ description(1:min(maxchar,length(description))) '...' ]; - end; - - userdata = ''; - enableWebDoc = fastif(isempty(plugin(iRow).webdoc), 'off', 'on'); - uilist = { uilist{:}, ... - { 'style' 'checkbox' 'string' '' 'tag' [ 'cb1' int2str(iRow) ] 'callback' callback }, ... - { 'style' 'checkbox' 'string' '' 'tag' [ 'cb2' int2str(iRow) ] 'callback' callback }, ... - { 'style' 'text' 'string' plugin(iRow).name }, ... - { 'style' 'text' 'string' plugin(iRow).version 'tag' 'latestversion' }, ... - { 'style' 'text' 'string' int2str(plugin(iRow).downloads) }, ... - { 'style' 'text' 'string' description }, ... - { 'style' 'pushbutton' 'string' 'Doc' 'enable' enableWebDoc 'callback' myweb(plugin(iRow).webdoc) } }; - geom = { geom{:}, lineGeom }; - geomvert = [ geomvert 1]; - pluginIndices = [ pluginIndices iRow ]; - end; - end; -end; - -evalStr = [ 'uisettxt(gcf, ''update'' , ''Update'' , ''rotation'', 90, ''fontsize'', 14);' ... - 'uisettxt(gcf, ''deactivate'' , ''Deactivate'' , ''rotation'', 90, ''fontsize'', 14);' ... - 'uisettxt(gcf, ''install'' , ''Install'' , ''rotation'', 90, ''fontsize'', 14);' ... - 'uisettxt(gcf, ''reactivate'' , ''Reactivate'' , ''rotation'', 90, ''fontsize'', 14);' ... - 'uisettxt(gcf, ''remove1'' , ''Remove'' , ''rotation'', 90, ''fontsize'', 14);' ... - 'set(findobj(gcf, ''tag'', ''title''), ''fontsize'', 16);' ... - 'tmpobj = findobj(gcf, ''userdata'', ''colortored'');' ... - 'set(tmpobj, ''Foregroundcolor'', [1 0 0]);' ... - 'tmppos = get(gcf, ''position'');' ... - 'set(gcf, ''position'', [tmppos(1:2) 800 tmppos(4)]);' ... - 'clear tmpobj tmppos;' ... - ]; - -if 1 - % version with button - if page == 1, enablePpage = 'off'; else enablePpage = 'on'; end; - if page*pluginsPerPage > numPlugin, enableNpage = 'off'; else enableNpage = 'on'; end; - callBackPpage = [ 'tmpobj = get(gcbf, ''userdata''); close gcbf; restartEeglabFlag = plugin_extract(tmpobj, [], ' int2str(page-1) '); clear tmpobj;' ]; - callBackNpage = [ 'tmpobj = get(gcbf, ''userdata''); close gcbf; restartEeglabFlag = plugin_extract(tmpobj, [], ' int2str(page+1) '); clear tmpobj;' ]; - - uilist = { uilist{:}, {} { 'width' 80 'align' 'left' 'Style', 'pushbutton', 'string', '< Prev. page', 'tag' 'ppage' 'callback', callBackPpage 'enable' enablePpage } }; - uilist = { uilist{:}, { 'width' 80 'align' 'left' 'stickto' 'on', 'Style', 'pushbutton', 'string', 'Next page >', 'tag' 'npage' 'callback', callBackNpage 'enable' enableNpage } }; - uilist = { uilist{:}, { 'width' 80 'align' 'right' 'Style', 'pushbutton', 'string', 'Cancel', 'tag' 'cancel' 'callback', 'close gcbf' } }; - uilist = { uilist{:}, { 'width' 80 'align' 'right' 'stickto' 'on' 'Style', 'pushbutton', 'tag', 'ok', 'string', 'OK', 'callback', 'set(gcbo, ''userdata'', ''retuninginputui'');' } }; - geom = { geom{:} [1] [1 1 1 1] }; - geomvert = [ geomvert 1 1]; - res = inputgui('uilist', uilist, 'geometry', geom, 'geomvert', geomvert, 'eval', evalStr, 'addbuttons', 'off', 'skipline', 'off', 'userdata', allPlugins); - - try, restartEeglabFlag = evalin('base', 'restartEeglabFlag;'); catch, end; - evalin('base', 'clear restartEeglabFlag;'); -else - % no buttons - res = inputgui('uilist', uilist, 'geometry', geom, 'geomvert', geomvert, 'eval', evalStr); -end; -if isempty(res), return; end; - -% decode inputs -% ------------- -for iRow = 1:length(pluginIndices) - plugin(pluginIndices(iRow)).install = res{(iRow-1)*2+1}; - plugin(pluginIndices(iRow)).remove = res{(iRow-1)*2+2}; -end; - -% install plugins -% --------------- -firstPlugin = 1; -for iRow = 1:length(plugin) - if plugin(iRow).install - restartEeglabFlag = true; - if ~firstPlugin, disp('---------------------------------'); end; firstPlugin = 0; - - if strcmpi(plugin(iRow).status, 'deactivated') - fprintf('Reactivating extension %s\n', plugin(iRow).name); - plugin_reactivate(plugin(iRow).foldername); - if plugin(iRow).installorupdate - res = questdlg2([ 'Extension ' plugin(iRow).foldername ' has been reactivated but' 10 'a new version is available. Do you want to install it?' ], 'Warning', 'No', 'Yes', 'Yes'); - if strcmpi(res, 'yes') - plugin_deactivate(plugin(iRow).foldername); - if plugin_install(plugin(iRow).zip, plugin(iRow).name, plugin(iRow).version) == -1 - plugin_reactivate(plugin(iRow).foldername); - else - plugin_remove(plugin(iRow).foldername); - end; - end; - end; - else - if plugin(iRow).installed - fprintf('Updating extension %s\n', plugin(iRow).name); - plugin_deactivate(plugin(iRow).foldername); - if plugin_install(plugin(iRow).zip, plugin(iRow).name, plugin(iRow).version) == -1 - plugin_reactivate(plugin(iRow).foldername); - else - plugin_remove(plugin(iRow).foldername); - end; - else - fprintf('Installing extension %s\n', plugin(iRow).name); - plugin_install(plugin(iRow).zip, plugin(iRow).name, plugin(iRow).version); - end; - end; - elseif plugin(iRow).remove - if ~firstPlugin, disp('---------------------------------'); end; firstPlugin = 0; - restartEeglabFlag = true; - - if strcmpi(plugin(iRow).status, 'deactivated') - fprintf('Removing extension %s\n', plugin(iRow).name); - plugin_remove(plugin(iRow).foldername); - else - fprintf('Deactivating extension %s\n', plugin(iRow).name); - plugin_deactivate(plugin(iRow).foldername); - end; - end; -end; - -function str = myweb(url); +function restartEeglabFlag = plugin_extract(type, pluginlist, page) - %if isempty(strfind(url, 'wiki')) - % str = [ 'web(''' url ''');' ]; - %else - str = [ 'web(''' url ''', ''-browser'');' ]; - %end; - +disp('The function plugin_extract has been deprecated and calls the plugin_menu function instead'); +plugin_menu(pluginlist); diff --git a/functions/adminfunc/plugin_getweb.m b/functions/adminfunc/plugin_getweb.m index 7ca600057..fdcd86605 100644 --- a/functions/adminfunc/plugin_getweb.m +++ b/functions/adminfunc/plugin_getweb.m @@ -1,69 +1,112 @@ -function plugin = plugin_getweb(type, pluginOri, mode) +% plugin_getweb - support function to get plugin information from the web -if nargin < 1, help plugin_getweb; return; end; -if nargin < 2, pluginOri = []; end; -if nargin < 3, mode = 'merge'; end; % 'merge' or 'newlist' +% Copyright (C) 2012- Arnaud Delorme +% +% 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 [plugin,eeglabVersionStatus] = plugin_getweb(type, pluginOri, varargin) +plugin = []; +eeglabVersionStatus = []; + +if nargin < 1, help plugin_getweb; return; end +if nargin < 2, pluginOri = []; end % convert plugin list format if necessary -if isfield(pluginOri, 'plugin'), pluginOri = plugin_convert(pluginOri); end; +if isfield(pluginOri, 'plugin'), pluginOri = plugin_convert(pluginOri); end -try - disp( [ 'Retreiving URL with ' type ' extensions...' ] ); - if strcmpi(type, 'import') - [tmp status] = plugin_urlread('http://sccn.ucsd.edu/wiki/Plugin_list_import'); - else - [tmp status] = plugin_urlread('http://sccn.ucsd.edu/wiki/Plugin_list_process'); - end; -catch, - error('Cannot connect to the Internet to retrieve extension list'); -end; +[~,dateTmp] = version; +if datenum(dateTmp) < 736583 + error( [ 'The plugin manager is only available for Matlab version 2016b and later versions.' 10 ... + 'Download plugins from the internet and unzip them in the plugin folder instead.' ] ); +end -% retreiving download statistics +% retrieving statistics +eeglab_options; try - disp( [ 'Retreiving download statistics...' ] ); - [stats status] = plugin_urlread('http://sccn.ucsd.edu/eeglab/plugin_uploader/plugin_getcountall.php'); - stats = textscan(stats, '%s%d%s%s'); -catch, - stats = {}; + disp( [ 'Retrieving download statistics...' ] ); + if exist('OCTAVE_VERSION', 'builtin') == 0 + [plugin, status] = plugin_urlread([ 'http://sccn.ucsd.edu/eeglab/plugin_uploader/plugin_getcountall_nowiki_json.php?type=' type '&upload=' num2str(option_showpendingplugins)]); + else + [plugin, status] = urlread([ 'http://sccn.ucsd.edu/eeglab/plugin_uploader/plugin_getcountall_nowiki_json.php?type=' type '&upload=' num2str(option_showpendingplugins)]); + end + if isempty(plugin) || isequal(plugin, 'Couldn''t make connection to DB.') + disp('Issue with retrieving statistics for extensions'); + plugin = []; + return; + end + try + plugin = jsondecode(plugin); + catch + disp('Issue with decoding plugin information, Octave 7.x required to decode JSON strings'); + end +catch disp('Cannot connect to the Internet to retrieve statistics for extensions'); -end; + return +end if status == 0 - error('Cannot connect to the Internet to retrieve extension list'); -end; + disp('Cannot connect to the Internet to retrieve extension list'); + return +end -% parse the web page -% ------------------ -try - plugin = parseTable(tmp); -catch - error('Cannot parse extension list - please contact eeglab@sccn.ucsd.edu'); -end; +%% rename fields for backward compabitiligy +renameField = { 'plugin' 'name'; + 'count' 'downloads'; + 'curversion' 'version'; + 'link' 'zip' }; -% find correspondance with plugin list -% ------------------------------------ if ~isempty(pluginOri) - currentNames = lower({ pluginOri.name }); -else currentNames = {}; -end; -allMatch = []; + currentNames = lower({ pluginOri.name }); +else + currentNames = {}; +end for iRow = 1:length(plugin) - % fix links - if isfield(plugin, 'zip'), plugin(iRow).zip = strrep(plugin(iRow).zip, '&', '&'); end; - - % get number of downloads - if ~isempty(stats) - indMatch = strmatch(plugin(iRow).name, stats{1}, 'exact'); - if ~isempty(indMatch) - plugin(iRow).downloads = stats{2}(indMatch(1)); - if length(stats) > 2 && ~isempty(stats{3}{indMatch(1)}) - plugin(iRow).version = stats{3}{indMatch(1)}; - plugin(iRow).zip = stats{4}{indMatch(1)}; - end; - else plugin(iRow).downloads = 0; - end; - else plugin(iRow).downloads = 0; - end; + + % rename fields + for iField = 1:size(renameField, 1) + if ~isfield(plugin, renameField{iField, 1}) + disp('Plugin list incomplete - maybe an issue with internet connection - aborting.'); + return + end + plugin(iRow).(renameField{iField, 2}) = plugin(iRow).(renameField{iField, 1}); + end + + % decode tags + plugin(iRow).rawtags = plugin(iRow).tags; + if ~isempty(plugin(iRow).rawtags) + tmpTags = textscan(plugin(iRow).rawtags, '%s', 'delimiter', ','); + plugin(iRow).tags = tmpTags{1}'; + end + + plugin(iRow).numrating = str2double(plugin(iRow).numrating); + plugin(iRow).rating = str2double(plugin(iRow).rating); + plugin(iRow).critical = str2double(plugin(iRow).critical); + plugin(iRow).downloads = str2double(plugin(iRow).downloads); + plugin(iRow).size = sscanf(plugin(iRow).size, '%f'); % Only numeric part is taken, possible KB or MB additions are ignored + plugin(iRow).webrating = [ 'https://sccn.ucsd.edu/eeglab/plugin_uploader/simplestar.php?plugin=' plugin(iRow).name '&version=' plugin(iRow).version ]; % match with existiting plugins indMatch = strmatch(lower(plugin(iRow).name), currentNames, 'exact'); @@ -74,8 +117,8 @@ plugin(iRow).status = 'notinstalled'; else if length(indMatch) > 1 - disp([ 'Warning: duplicate extension ' plugin(iRow).name ' instaled' ]); - end; + disp([ 'Warning: duplicate extension ' plugin(iRow).name ' installed' ]); + end plugin(iRow).currentversion = pluginOri(indMatch).currentversion; plugin(iRow).foldername = pluginOri(indMatch).foldername; plugin(iRow).status = pluginOri(indMatch).status; @@ -84,101 +127,26 @@ plugin(iRow).installorupdate = 0; else plugin(iRow).installorupdate = 1; - end; - allMatch = [ allMatch indMatch(:)' ]; - end; - -end; - -% put all the installed plugins first -% ----------------------------------- -if ~isempty(plugin) - [tmp reorder] = sort([plugin.installed], 'descend'); - plugin = plugin(reorder); -% plugin(1).currentversion = '0.9'; -% plugin(1).version = '1'; -% plugin(1).foldername = 'test'; -% plugin(1).installed = 1; -% plugin(1).installorupdate = 1; -% plugin(1).description = 'test'; -% plugin(1).webdoc = 'test'; -% plugin(1).name = 'test'; -end; + end + end +end +plugin = rmfield(plugin, renameField(:,1)'); -if strcmpi(mode, 'merge') && ~isempty(pluginOri) - indices = setdiff([1:length(pluginOri)], allMatch); - fields = fieldnames(pluginOri); - lenPlugin = length(plugin); - - for indPlugin = 1:length(indices) - for indField = 1:length(fields) - value = getfield(pluginOri, { indices(indPlugin) }, fields{ indField }); - plugin = setfield(plugin , { lenPlugin+indPlugin }, fields{ indField }, value); - end; - end; -end; - -% parse the web table -% =================== -function plugin = parseTable(tmp); +% handle the special case of EEGLAB version +indEEGLAB = cellfun(@(x)isequal(x, 'eeglab'), lower( { plugin.name } )); +eeglabVersionStatus = plugin(indEEGLAB); +plugin(indEEGLAB) = []; -plugin = []; -if isempty(tmp), return; end; +% remove plugins with no zip file +% ------------------------------- +plugin(cellfun(@isempty, {plugin.zip })) = []; -% get table content -% ----------------- -tableBeg = findstr('Plug-in name', tmp); -tableEnd = findstr('', tmp(tableBeg:end)); -tableContent = tmp(tableBeg:tableBeg+tableEnd-2); -endFirstLine = findstr('', tableContent); -tableContent = tableContent(endFirstLine(1)+5:end); +function plugin = plugin_convert(pluginOri) -% parse table entries -% ------------------- -posBegRow = findstr('' , tableContent); -posEndRow = findstr('', tableContent); -if length(posBegRow) ~= length(posEndRow) || isempty(posBegRow) - error('Cannot connect to the Internet to retrieve plugin list'); -end; -for iRow = 1:length(posBegRow) - rowContent = tableContent(posBegRow(iRow)+4:posEndRow(iRow)-1); - posBegCol = findstr('' , rowContent); - posEndCol = findstr('', rowContent); - for iCol = 1:length(posBegCol) - table{iRow,iCol} = rowContent(posBegCol(iCol)+4:posEndCol(iCol)-1); - end; -end; - -%% extract zip link and plugin name from first column -% -------------------------------------------------- -%href="http://www.unicog.org/pm/uploads/MEG/ADJUST_PLUGIN.zip" class="external text" title="http://www.unicog.org/pm/uploads/MEG/ADJUST_PLUGIN.zip" rel="nofollow">ADJUST PLUGIN 500000 && ~forceInstall + res = questdlg2( [ 'Extension ' name ' size is ' num2str(ceil(pluginsize/100)/10) 'MB. Are you sure' 10 ... + 'you want to download this extension?' ], 'Warning', 'No', 'Yes', 'Yes'); + if strcmpi(res, 'no'), fprintf([ 'Skipping ' name ' extension installation\n' ]); + result = -1; + return; + end + end + try - pluginSize = plugin_urlsize(zipfilelink); - pluginSizeStr = num2str(round(pluginSize/100000)/10); - if pluginSize > 500000 && depth > 1 && ~forceInstall - res = questdlg2( [ 'Extension ' name ' size is ' pluginSizeStr 'MB. Are you sure' 10 ... - 'you want to download this extension?' ], 'Warning', 'No', 'Yes', 'Yes'); - if strcmpi(res, 'no'), fprintf([ 'Skipping ' name ' extension instalation\n' ]); result = -1; return; end; - end; - catch, - msg = [ 'Could not download extension. Host site might be' 10 'unavailable, too slow or you do not have permission' 10 'to write in the EEGLAB plugin folder. Try again' 10 'just in case or use a faster connection.' ]; - if ~forceInstall - warndlg2(msg); + if exist('OCTAVE_VERSION', 'builtin') == 0 + plugin_urlread(['http://sccn.ucsd.edu/eeglab/plugin_uploader/plugin_increment.php?plugin=' name '&version=' version ]); + plugin_urlwrite( zipfilelink, fullfile(generalPluginPath, zipfile)); else - disp(msg); - end; - result = -1; - return; - end; - disp([ 'Downloading extension ' name '(' pluginSizeStr 'Mb)...' ]); - - try - plugin_urlread(['http://sccn.ucsd.edu/eeglab/plugin_uploader/plugin_increment.php?plugin=' name '&version=' version ]); - plugin_urlwrite( zipfilelink, fullfile(generalPluginPath, zipfile)); - catch, - msg = [ 'Could not download extension. Host site might be' 10 'unavailable or you do not have permission' 10 'to write in the EEGLAB plugin folder. Try again' 10 'just in case.' ]; + urlread(['http://sccn.ucsd.edu/eeglab/plugin_uploader/plugin_increment.php?plugin=' name '&version=' version ]); + urlwrite( zipfilelink, fullfile(generalPluginPath, zipfile)); + end + catch + msg = [ 'Could not download extension. Host site might be' 10 ... + 'unavailable, too slow or you do not have permission' 10 ... + 'to write in the EEGLAB plugin folder. Try again' 10 ... + 'just in case or use a faster connection.' 10 10 ... + 'Alternatively install the plugin manually by downloading' 10 ... + 'it at http://sccn.ucsd.edu/wiki/EEGLAB_Extensions_and_plug-ins' 10 ... + 'unziping it in the eeglab/plugin folder and restarting eeglab']; if ~forceInstall warndlg2(msg); else disp(msg); - end; + end result = -1; return; - end; + end % unzip plugin % ------------ @@ -61,10 +104,10 @@ warndlg2(msg); else disp(msg); - end; + end result = -1; return; - end; + end disp([ 'Unzipping extension file... ']); unzip(fullfile(generalPluginPath, zipfile), newPluginPath); @@ -76,7 +119,7 @@ pluginContent = dir(newPluginPath); if length(pluginContent) > 3 return; - end; + end for index = 1:length(pluginContent) if ~strcmpi(pluginContent(index).name, '.') && ~strcmpi(pluginContent(index).name, '..') fullFolder = fullfile(newPluginPath, pluginContent(index).name); @@ -84,8 +127,8 @@ % move files from folder movefile(fullfile(fullFolder, '*'), newPluginPath); rmdir(fullFolder, 's'); - end; - end; - end; + end + end + end fprintf('Extension %s version %s now installed\n', name, version); - \ No newline at end of file + diff --git a/functions/adminfunc/plugin_installstartup.m b/functions/adminfunc/plugin_installstartup.m deleted file mode 100644 index 1547d41a6..000000000 --- a/functions/adminfunc/plugin_installstartup.m +++ /dev/null @@ -1,62 +0,0 @@ -% plugin_installstartup() - install popular toolboxes when EEGLAB starts -% -% Usage: -% >> restartEeglabFlag = plugin_installstartup; % pop up window -% -% Outputs: -% restartEeglabFlag - [0|1] restart EEGLAB -% -% Author: Arnaud Delorme, SCCN, INC, UCSD, Oct. 29, 2013- - -% Copyright (C) 2013 Arnaud Delorme, SCCN, INC, UCSD, arno@salk.edu -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -function restartEeglabFlag = plugin_installstartup - -% { 'style' 'checkbox' 'string' 'Neuroelectromagnetic Forward Head Modeling Toolbox (NFT): Advanced source localization tools - beta (Zeynep Akalin Acar, 100 Mb)' 'value' 1 'enable' 'on' } ... - - uilist = { { 'style' 'text' 'String' 'Download and install some popular third party EEGLAB plug-ins' 'fontweight', 'bold','tag', 'title'} ... - { } ... - { 'style' 'checkbox' 'string' 'Brain Vision Analyser data import plugin (40 Kb)' 'value' 1 'enable' 'on' } ... - { 'style' 'checkbox' 'string' 'ANT data import plugin (800 Kb)' 'value' 1 'enable' 'on' } ... - { 'style' 'checkbox' 'string' 'Measure Projection Toolbox (MPT) for ulti-subject ICA analysis (415 Mb)' 'value' 1 'enable' 'on' } ... - { 'style' 'checkbox' 'string' 'Source Information Flow Toolbox (SIFT) for causal analysis of EEG sources (600 Mb)' 'value' 1 'enable' 'on' } ... - { 'style' 'checkbox' 'string' 'BCILAB for real-time and offline BCI platform (200 Mb)' 'value' 1 'enable' 'on' } ... - { 'style' 'checkbox' 'string' 'LIMO for linear analysis of MEEG data using single trials (2.5 Mb)' 'value' 1 'enable' 'on' } ... - { } ... - { 'style' 'radiobutton' 'string' 'Do not show this query again' 'value' 0 } ... - {} ... - { 'style' 'text' 'String' 'Note: manage plug-in tools using EEGLAB menu item, "File > Plug-ins > Manage plug-ins"' } ... - {} ... - { 'Style', 'pushbutton', 'string', 'Do not install now', 'tag' 'cancel' 'callback', 'set(gcbf, ''userdata'', ''cancel'');' } { } ... - { 'Style', 'pushbutton', 'string', 'Install plugins now', 'tag', 'ok', 'callback', 'set(gcbf, ''userdata'', ''ok'');' } ... - }; - - geomline = [1]; - geom = { [1] [1] geomline geomline geomline geomline geomline geomline [1] geomline [1] [1] [1] [1 1 1]}; - geomvert = [ 1 0.5 1 1 1 1 1 1 0.3 1 0.3 1 1 1]; - - %result = inputgui( 'geometry', geom, 'uilist', uilist, 'helpcom', 'pophelp(''plugin_installstartup'')', 'title', 'Install popular plugins', 'geomvert', geomvert, 'eval', evalstr); - fig = figure('visible', 'off'); - [tmp1 tmp2 handles] = supergui( 'geomhoriz', geom, 'uilist', uilist, 'title', 'Install popular plugins', 'geomvert', geomvert, 'fig', fig); %, 'eval', evalstr); - set(findobj(fig, 'tag', 'title'), 'fontsize', 16); - waitfor( fig, 'userdata'); - - % decode inputs - handles - results = cellfun(@(x)(get - get(handles, 'value') - \ No newline at end of file diff --git a/functions/adminfunc/plugin_managedeactivated.m b/functions/adminfunc/plugin_managedeactivated.m deleted file mode 100644 index 957dc4c24..000000000 --- a/functions/adminfunc/plugin_managedeactivated.m +++ /dev/null @@ -1,89 +0,0 @@ -function restartEeglabFlag = plugin_managedeactivated(pluginlist) - -% type may be 'import' or 'process' -restartEeglabFlag = false; -plugin = plugin_getweb('import' , pluginlist); -plugin = plugin_getweb('process', plugin); - -for iRow = 1:length(plugin) - plugin(iRow).remove = 0; - plugin(iRow).reactivate = 0; -end; - -if isempty(strmatch('deactivated', { plugin.status }, 'exact')) - warndlg2('There are no deactivated plugins'); - return; -end; - -maxchar = 60; -uilist = { {} { 'style' 'text' 'string' ' List of deactivated plugins ' 'fontweight' 'bold' 'fontsize' 18 'tag' 'title' } }; -uilist = { uilist{:} ... - { 'style' 'text' 'string' 'I' 'tag' 'reactivate' } ... - { 'style' 'text' 'string' 'I' 'tag' 'remove1' } ... - { 'style' 'text' 'string' 'Plugin' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Version' 'tag' 'verweb' 'fontweight' 'bold' } ... - { 'style' 'text' 'string' 'Description' 'fontweight' 'bold' } {}}; -lineGeom = [ 0.28 0.28 0.95 0.8 3 0.35 ]; -geom = { [1 5.5] lineGeom }; -geomvert = [1 1]; -pluginIndices = []; -for iRow = 1:length(plugin) - if strcmpi(plugin(iRow).status, 'deactivated') - % text for description - description = plugin(iRow).description; - if length(description) > maxchar+2 - description = [ description(1:min(maxchar,length(description))) '...' ]; - end; - - cb = [ 'tmptag = get(gcbo, ''tag'');' ... - 'if tmptag(3) == ''1'', tmptag(3) = ''2''; else tmptag(3) = ''1''; end;' ... - 'set(findobj(gcbf, ''tag'', tmptag), ''value'', ~get(gcbo, ''value''));' ]; - userdata = ''; - enableWebDoc = fastif(isempty(plugin(iRow).webdoc), 'off', 'on'); - uilist = { uilist{:}, ... - { 'style' 'checkbox' 'string' '' 'tag' [ 'cb1' int2str(iRow) ] 'callback' cb }, ... - { 'style' 'checkbox' 'string' '' 'tag' [ 'cb2' int2str(iRow) ] 'callback' cb }, ... - { 'style' 'text' 'string' plugin(iRow).name }, ... - { 'style' 'text' 'string' plugin(iRow).version 'tag' 'latestversion' }, ... - { 'style' 'text' 'string' description }, ... - { 'style' 'pushbutton' 'string' 'Doc' 'enable' enableWebDoc 'callback' [ 'web(''' plugin(iRow).webdoc ''');' ] } }; - geom = { geom{:}, lineGeom }; - geomvert = [ geomvert 1]; - pluginIndices = [ pluginIndices iRow ]; - end; -end; - -evalStr = [ 'uisettxt(gcf, ''reactivate'' , ''Reactivate'' , ''rotation'', 90, ''fontsize'', 14);' ... - 'uisettxt(gcf, ''remove1'' , ''Remove'' , ''rotation'', 90, ''fontsize'', 14);' ... - 'tmppos = get(gcf, ''position''); set(gcf, ''position'', [tmppos(1:2) max(700, tmppos(3)) tmppos(4)]);' ... - 'set(findobj(gcf, ''tag'', ''title''), ''fontsize'', 16);' ... - 'tmpobj = findobj(gcf, ''userdata'', ''colortored'');' ... - 'set(tmpobj, ''Foregroundcolor'', [1 0 0]);' ... - 'clear tmppos tmpobj;']; - -res = inputgui('uilist', uilist, 'geometry', geom, 'geomvert', geomvert, 'eval', evalStr); -if isempty(res), return; end; - -% decode inputs -% ------------- -for iRow = 1:length(pluginIndices) - plugin(pluginIndices(iRow)).reactivate = res{(iRow-1)*2+1}; - plugin(pluginIndices(iRow)).remove = res{(iRow-1)*2+2}; -end; - -% install plugins -% --------------- -firstPlugin = 1; -for iRow = 1:length(plugin) - if plugin(iRow).remove - if ~firstPlugin, disp('---------------------------------'); end; firstPlugin = 0; - - fprintf('Removing plugin %s\n', plugin(iRow).name); - plugin_remove(plugin(iRow).foldername); - elseif plugin(iRow).reactivate - if ~firstPlugin, disp('---------------------------------'); end; firstPlugin = 0; - restartEeglabFlag = true; - fprintf('Reactivating plugin %s\n', plugin(iRow).name); - plugin_reactivate(plugin(iRow).foldername); - end; -end; diff --git a/functions/adminfunc/plugin_menu.m b/functions/adminfunc/plugin_menu.m new file mode 100644 index 000000000..c18718006 --- /dev/null +++ b/functions/adminfunc/plugin_menu.m @@ -0,0 +1,250 @@ +% PLUGIN_MENU - main function to install EEGLAB plugins +% +% To install plugins from the command line, type in +% +% plugin_askinstall('xxxxxx', [], true); % with xxxx being the name of the plugin +% +% Usage: plugin_menu(PLUGINLIST); % pop up gui + +% Copyright (C) 2019 Arnaud Delorme +% +% 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 restartEeglabFlag = plugin_menu(pluginlist) + +FONTSIZE = 0; % set to 4 for high-res screen + +% type may be 'import' or 'process' +restartEeglabFlag = false; +plugin = plugin_getweb('plugin_check', pluginlist); +if isempty(plugin) + errordlg2(['Either you are offline, a firewall is blocking EEGLAB from accessing its' char(10) ... + 'plugin server or there is a problem with Java. For Java problems, refer to' char(10) ... + 'https://github.com/sccn/eeglab/issues/20']); + return; +end + +% sort plugins by download score +[~,scoreOrder] = sort([ plugin.downloads ], 2, 'descend'); +plugin = plugin(scoreOrder); + +% sort plugins by download score +[~, scoreOrder] = sort([ plugin.downloads ], 2, 'descend'); +plugin = plugin(scoreOrder); + +% ------------------ +% plugins to install +% ------------------ +eeglab_options; +if option_htmlingraphics + disp('GUI slow to pop up? Try disabling HTML graphics in the Preferences menu (first show advanced options).') + search_icon_path = ['   Search']; +else + search_icon_path = 'Search'; +end +for iRow = 1:length(plugin) + if option_htmlingraphics + plugin(iRow).text = [ ' ' htmlrating(plugin(iRow).rating, plugin(iRow).numrating) ]; + if plugin(iRow).installed + if plugin(iRow).installorupdate + plugin(iRow).text = [ plugin(iRow).text '' ]; + else + plugin(iRow).text = [ plugin(iRow).text '' ]; + end + end + plugin(iRow).text = [ plugin(iRow).text plugin(iRow).name ' v' plugin(iRow).version ]; + if plugin(iRow).installed && plugin(iRow).installorupdate + plugin(iRow).text = [ plugin(iRow).text ' update available ' ]; + end + plugin(iRow).text = [ plugin(iRow).text ' (' int2str(plugin(iRow).downloads) ' downloads' ]; + if ~isnan(plugin(iRow).numrating) && plugin(iRow).numrating + plugin(iRow).text = [ plugin(iRow).text '; ' int2str(plugin(iRow).numrating) ' rating' ]; + end + plugin(iRow).text = [ plugin(iRow).text ')' ]; + plugin(iRow).strsearch = lower([ plugin(iRow).name plugin(iRow).rawtags plugin(iRow).description ]); + else + plugin(iRow).text = ''; + if plugin(iRow).installed + plugin(iRow).text = [ plugin(iRow).text '****' ]; + end + plugin(iRow).text = [ plugin(iRow).text plugin(iRow).name ' v' plugin(iRow).version ]; + if plugin(iRow).installed && plugin(iRow).installorupdate + plugin(iRow).text = [ plugin(iRow).text ' update available ' ]; + end + plugin(iRow).text = [ plugin(iRow).text ' (' int2str(plugin(iRow).downloads) ' downloads)' ]; + if plugin(iRow).installed + plugin(iRow).text = [ plugin(iRow).text '****' ]; + end + plugin(iRow).strsearch = lower([ plugin(iRow).name plugin(iRow).rawtags plugin(iRow).description ]); + end +end + +%cb_select = 'tmpobj = get(gcbf, ''userdata''); tmpstr = tmpobj(get(gcbo, ''value'')).longdescription; tmpstr = textwrap(findobj(gcbf, ''tag'', ''description''), {tmpstr}); set(findobj(gcbf, ''tag'', ''description''), ''string'', tmpstr); clear tmpobj tmpstr;'; +filterList1 = { 'No install status filter' ... + 'Show installed only' ... + 'Show non installed only' }; +filterList2 = { 'No topic filter' ... + 'Filter by import' ... + 'Filter by export' ... + 'Filter by artifact' ... + 'Filter by ica' ... + 'Filter by preprocessing' ... + 'Filter by erp' ... + 'Filter by source' ... + 'Filter by study' ... + 'Filter by time-freq' ... + 'Filter by other' }; + +uilist = { + { 'style', 'text', 'string', 'List of plugins (bolded means installed)' 'fontweight' 'bold' } ... + { 'style', 'popupmenu', 'string', filterList1 'callback' 'plugin_uifilter(gcbf);' 'tag' 'filter1' } ... + { 'style', 'popupmenu', 'string', filterList2 'callback' 'plugin_uifilter(gcbf);' 'tag' 'filter2' } ... + { 'style', 'pushbutton', 'string', search_icon_path 'callback' 'plugin_search(gcbf);' 'tag' 'search' 'tooltipstring' 'Enter search term' } ... + { 'style', 'listbox', 'string', { plugin.text } 'callback' 'plugin_uiupdate(gcbf);' 'Min', 0, 'Max', 2, 'value' [] 'tag', 'pluginlist' 'fontsize', 16, 'tooltipstring', [ 'Bold plugins are installed.' 10 'Red plugins need updating.' 10 '(Wong font size? Change it in plugin_menu.m)' ] } ... + { 'style', 'pushbutton', 'string', 'Rate this plugin' 'tag' 'rating' } ... + { 'style', 'pushbutton', 'string', 'Web documentation' 'tag' 'documentation' } ... + { 'style', 'pushbutton', 'string', 'Upload new plugin' 'tag' 'upload' 'callback' 'web(''http://sccn.ucsd.edu/eeglab/plugin_uploader/upload_form.php'', ''-browser'');'} ... + { 'style', 'text', 'string', 'Tags:' 'fontweight' 'bold' } ... + { 'style', 'text', 'string', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 'tag' 'tags' } ... + { 'style', 'text', 'string', 'Status:' 'fontweight' 'bold' } ... + { 'style', 'text', 'string', 'Installed' 'tag' 'status'} ... + { 'style', 'text', 'string', 'Size:' 'fontweight' 'bold' } ... + { 'style', 'text', 'string', 'Size is not large' 'tag' 'size'} ... + { 'style', 'text', 'string', 'Description of the plugin:' 'fontweight' 'bold' } ... + { 'style', 'text', 'string', [ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 10 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 10 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 10 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ] 'tag' 'description' } ... + {} ... + {} ... + { 'Style', 'pushbutton', 'string', 'Cancel', 'tag' 'cc' 'callback', 'close gcbf' } ... + { 'Style', 'pushbutton', 'tag', 'rmbut', 'string', 'Remove', 'callback', 'set(findobj(gcbf, ''tag'', ''install''), ''userdata'', ''remove'');' 'enable' 'off ' } ... + { 'Style', 'pushbutton', 'tag', 'install', 'string', 'Install/Update', 'callback', 'set(gcbo, ''userdata'', ''install'');' 'userdata' 'test' 'enable' 'off' } ... + }; + +usrDat.allplugins = plugin; +usrDat.selectedplugins = plugin; +usrDat.selection = []; +fig = figure('visible', 'off'); +supergui('fig', fig, 'uilist', uilist, 'geomhoriz', {[0.9 0.5 0.5 0.5] 1 [1 1 1] [0.2 1] [0.2 1] [0.2 1] 1 1 1 [0.43 0.37 0.4 0.5]}, 'geomvert', [1 10 1 1 1 1 1 2.5 1 1], 'userdata', usrDat); +%pos = get(fig, 'position'); +%set(fig, 'position', [pos(1) pos(2) pos(3)/841*200 pos(4) ]); + +% Remove text +set(findobj(fig, 'tag', 'tags'), 'string', ''); +set(findobj(fig, 'tag', 'status'), 'string', ''); +set(findobj(fig, 'tag', 'size'), 'string', ''); +set(findobj(fig, 'tag', 'description'), 'string', 'Click on a plugin to show its description'); + +set(fig, 'visible', 'on'); +waitfor( findobj('parent', fig, 'tag', 'install'), 'userdata'); + +% Cancel +if ~(ishandle(fig)), return; end % Check if figure still exist + +% Check if install or remove +removeOrInstall = get(findobj('parent', fig, 'tag', 'install'), 'userdata'); +if isempty(removeOrInstall) + removeOrInstall = 'remove'; + ButtonName = questdlg2( [ 'Are you sure you want to remove the selected plugins?' 10 'All modification you might have made to the code will be lost.'], ... + 'Removal confirmation', 'No', 'Yes', 'No' ); + if strcmpi(ButtonName, 'No') + close(fig); + return + end +end + +usrDat = get(fig, 'userdata'); +close(fig); + +% set flag in plugins +plugin = usrDat.selectedplugins; +plugin(1).install = []; +plugin(1).remove = []; +for iSelect = 1:length(usrDat.selection) + pInd = usrDat.selection(iSelect); + if ~plugin(pInd).installed + plugin(pInd).install = true; + else + % install or update based on which button was pressed + if strcmpi(removeOrInstall, 'install') + if plugin(pInd).installorupdate + plugin(pInd).install = true; + else + fprintf('Skipping install for plugin %s as there is no update available\n', plugin(pInd).name); + end + else + plugin(pInd).remove = true; + end + end +end + +% install plugins +% --------------- +firstPlugin = 1; +for iRow = 1:length(plugin) + if ~isempty(plugin(iRow).install) && plugin(iRow).install + restartEeglabFlag = true; + if ~firstPlugin, disp('---------------------------------'); end; firstPlugin = 0; + + if plugin(iRow).installed + fprintf('Updating extension %s\n', plugin(iRow).name); + if plugin_install(plugin(iRow).zip, plugin(iRow).name, plugin(iRow).version, plugin(iRow).size) ~= -1 + plugin_remove(plugin(iRow).foldername); + end + else + fprintf('Installing extension %s\n', plugin(iRow).name); + plugin_install(plugin(iRow).zip, plugin(iRow).name, plugin(iRow).version, plugin(iRow).size); + end + elseif ~isempty(plugin(iRow).remove) && plugin(iRow).remove + if ~firstPlugin, disp('---------------------------------'); end; firstPlugin = 0; + restartEeglabFlag = true; + + fprintf('Removing extension %s\n', plugin(iRow).name); + plugin_remove(plugin(iRow).foldername); + end +end + +function str = htmlrating(rating, numRating) + roundRating = round(rating); + if isempty(roundRating) || isnan(roundRating) || numRating == 0 + str = 'no rating  - '; + else + str = ''; + for i=1:roundRating + str = [ str '' ]; + end + str = [ str '' ]; + for i=roundRating+1:5 + str = [ str '' ]; + end + str = [ str ' - ' ]; + end + +function str = myweb(url); + + %if isempty(strfind(url, 'wiki')) + % str = [ 'web(''' url ''');' ]; + %else + str = [ 'web(''' url ''', ''-browser'');' ]; + %end diff --git a/functions/adminfunc/plugin_movepath.m b/functions/adminfunc/plugin_movepath.m new file mode 100644 index 000000000..19e72f528 --- /dev/null +++ b/functions/adminfunc/plugin_movepath.m @@ -0,0 +1,136 @@ +%PLUGIN_MOVEPATH- Given a path to a plugin folder, this function will +% put the plugin at the bottom of the path. +% +% Usage: +% plugin_movepath('x','begin'); % Put plugin 'x' at the top of the path +% plugin_movepath('x','end'); % Put plugin 'x' at the bottom of the path +% plugin_movepath('x','begin','warns',1); % Put plugin 'x' at the top of the path and show warnings +% +% Inputs: +% foldername - [string] Plugin name or part of it +% pluginpos - {'begin','end'} Position to move the plugin in the path. +% To the top ('begin') or to the bottom ('end'). +% Optional inputs: +% warns -[0,1] Allow display [1] or do not display [0] warnings. +% Warnings are restored at the end of the process. Default[0] +% Outputs: +% oldpath - Original MATLAB path before entering this function +% newpath - MATLAB path after being modified by this function +% +% Author: Ramon Martinez-Cancino and Arnaud Delorme, SCCN, 2016 +% +% Copyright (C) 2016 Ramon Martinez-Cancino,INC, SCCN +% +% 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[oldpath, newpath] = plugin_movepath(foldername,pluginpos, varargin) +oldpath = []; newpath = []; + +try + options = varargin; + if ~isempty( varargin ), + for i = 1:2:numel(options) + g.(options{i}) = options{i+1}; + end + else g = []; end +catch + disp('plugin_movepath() error: calling convention {''key'', value, ... } error'); return; +end + +try g.warns; catch, g.warns = 0; end; % NO warnings by default + +% Checking entries +if sum(strcmp(pluginpos,{'begin','end'})) ~= 1 + fprintf(2,'plugin_movepath error: Invalid function argument\n'); + return; +end + +% Look in the plugin list for the plugin name provided +global PLUGINLIST +hitindx = find(~cellfun(@isempty,strfind(lower({PLUGINLIST.plugin}),lower(foldername)))); +if isempty(hitindx) + fprintf(2,'plugin_movepath error: Unidentified plugin folder\n') + return; +else + eeglabfolder = fileparts(which('eeglab.m')); + pluginfolder = fullfile(eeglabfolder,'plugins',PLUGINLIST(hitindx).foldername ); +end + +% Backing up old path +if ismatlab + oldpath = matlabpath; +else + oldpath = path; +end + +% Retrieving path +comp = computer; +if strcmpi(comp(1:2), 'PC') + newpathtest = [ pluginfolder ';' ]; +else + newpathtest = [ pluginfolder ':' ]; +end +ind = strfind(oldpath, newpathtest); + +% Checking out if the work is already done +if strcmp(pluginpos,'begin') && ind == 1, return; end +if strcmp(pluginpos,'end') && strcmp(oldpath(end-length(pluginfolder):end),pluginfolder), return; end + +% Shooting down warnings +if ~g.warns + tmpwarn = warning; + warning off; +end + +% Remove folder and subfolders from path +rmpath(genpath(pluginfolder)); + +% Add folder to the path again in the requested position + if strcmp(pluginpos,'begin') + addpath(genpath(pluginfolder),'-begin'); + fprintf(1,['EEGLAB warning: to avoid name conflict ' PLUGINLIST(hitindx).foldername ' functions relocated at the end of the path\n']); + elseif strcmp(pluginpos,'end') + addpath(genpath(pluginfolder),'-end'); + fprintf(1,['EEGLAB warning: to avoid name conflict ' PLUGINLIST(hitindx).foldername ' functions relocated at the end of the path\n']); + end + + % Restoring warnings + if ~g.warns + warning(tmpwarn); + end + + newpath = path; % Retrieving new path + + % required here because path not added yet +% to the admin folder +function res = ismatlab; + +v = version; +if v(1) > '4' + res = 1; +else + res = 0; +end diff --git a/functions/adminfunc/plugin_reactivate.m b/functions/adminfunc/plugin_reactivate.m deleted file mode 100644 index b4283cd5c..000000000 --- a/functions/adminfunc/plugin_reactivate.m +++ /dev/null @@ -1,16 +0,0 @@ -function plugin_reactivate(foldername); - - % get plugin path - % --------------- - fullpluginfolder = fullfile(fileparts(which('eeglab.m')), 'deactivatedplugins', foldername); - if ~exist(fullpluginfolder) - error([ 'Could not find folder ' foldername 'in deactivatedplugins folder' ]); - end; - - disp([ 'Moving plugin ' foldername ' to plugins folder' ]); - fulldeactivatedpluginfolder = fullfile(fileparts(which('eeglab.m')), 'plugins'); - try - movefile(fullpluginfolder, fulldeactivatedpluginfolder); - catch - eeglab_error; - end; \ No newline at end of file diff --git a/functions/adminfunc/plugin_remove.m b/functions/adminfunc/plugin_remove.m index a39683f2a..120f94c3d 100644 --- a/functions/adminfunc/plugin_remove.m +++ b/functions/adminfunc/plugin_remove.m @@ -1,15 +1,47 @@ -function plugin_remove(foldername); +% Plugin support function to remove plugin + +% Copyright (C) 2012- Arnaud Delorme +% +% 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 plugin_remove(foldername) % get plugin path % --------------- - fullpluginfolder = fullfile(fileparts(which('eeglab.m')), 'deactivatedplugins', foldername); + fullpluginfolder = fullfile(fileparts(which('eeglab.m')), 'plugins', foldername); if ~exist(fullpluginfolder) - error([ 'Could not find folder ' foldername ' in deactivatedplugins folder' ]); - end; + error([ 'Could not find folder ' foldername ' in plugins folder' ]); + end disp([ 'Removing plugin folder ' foldername ]); try + rmpath(fullpluginfolder); + warning off; rmdir(fullpluginfolder, 's'); + warning on; catch eeglab_error; - end; \ No newline at end of file + end diff --git a/functions/adminfunc/plugin_search.m b/functions/adminfunc/plugin_search.m new file mode 100644 index 000000000..5937a4053 --- /dev/null +++ b/functions/adminfunc/plugin_search.m @@ -0,0 +1,71 @@ +% PLUGIN_SEARCH - support function for plugin_menu + +% Copyright (C) 2019 Arnaud Delorme +% +% 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 plugin_search(fig) + +tmpobj = get(fig, 'userdata'); +allPlugins = tmpobj.allplugins; + +uistyle = get(findobj(fig, 'tag', 'search'), 'style'); +if strcmpi(uistyle, 'pushbutton') + set(findobj(fig, 'tag', 'search'), 'style', 'edit', 'string', ''); + return; +end + +searchString = lower(get(findobj(fig, 'tag', 'search'), 'string')); +if isempty(searchString), return; end +searchString = textscan(searchString, '%s'); +searchString = searchString{1}; + +% reset filters +set(findobj(fig, 'tag', 'filter1'), 'value', 1); +set(findobj(fig, 'tag', 'filter2'), 'value', 1); + +% search +if isempty(searchString) + selectedPlugins = allPlugins; +else + selectedPluginsIndex = []; + for iSearch = 1:length(searchString) + res = strfind( { allPlugins.strsearch }, searchString{iSearch}); + if isempty(selectedPluginsIndex) + selectedPluginsIndex = find(~cellfun(@isempty, res)); + else + selectedPluginsIndex = intersect(selectedPluginsIndex, find(~cellfun(@isempty, res))); + end + end + selectedPlugins = allPlugins(selectedPluginsIndex); +end + +% update GUI +set(findobj(fig, 'tag', 'pluginlist'), 'string', { selectedPlugins.text }, 'value', []); +tmpobj.selection = []; +tmpobj.selectedplugins = selectedPlugins; + +set(fig, 'userdata', tmpobj); diff --git a/functions/adminfunc/plugin_status.m b/functions/adminfunc/plugin_status.m new file mode 100644 index 000000000..62009b18e --- /dev/null +++ b/functions/adminfunc/plugin_status.m @@ -0,0 +1,92 @@ +% PLUGIN_STATUS- Given the name of a plugin(or part of it), returns +% the status (e.g. [0]not installed, [1]installed) +% Inputs: +% pluginname - {string} Name (or part of it) of plugin of interest +% +% Optional inputs: +% exactmatch - [0,1] Force the function to look for an exact match of +% the name provided in the input 'pluginname' +% {default: 0 = not exact match enforced} +% Outputs: +% +% status - [Vector 1xnumber of plugins]. 0 = Not installed, +% 1 = Installed +% pluginnameout - Name of the plugins in 'status'. +% pluginstruct - If the plugin(s) in 'pluginname' is installed, the function +% provide here a cell (one cell per plugin in 'status') array +% of structures with the following fields: +% {plugin, version, foldername, funcname, status} +% +% Author: Ramon Martinez-Cancino SCCN, 2018 +% +% Copyright (C) 2018 Ramon Martinez-Cancino,INC, SCCN +% +% 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[status, pluginnameout, pluginstruct] = plugin_status(pluginname, varargin) +status = []; pluginstruct = []; pluginnameout = []; + +try + options = varargin; + if ~isempty( varargin ) + for i = 1:2:numel(options) + g.(options{i}) = options{i+1}; + end + else + g = []; + end +catch + disp('plugin_status() error: calling convention {''key'', value, ... } error'); return; +end + +try g.exactmatch; catch, g.exactmatch = 0; end % Enforces exact match with the name provided + +% Look in the plugin list for the plugin name provided +global PLUGINLIST +if ~isempty(PLUGINLIST) + if g.exactmatch + hitindx = find(strcmp(pluginname,{PLUGINLIST.plugin})); + pluginnameout = pluginname; + else + hitindx = find(~cellfun(@isempty,strfind(lower({PLUGINLIST.plugin}),lower(pluginname)))); + end + + if isempty(hitindx) + status = 0; + return; + else + pluginstatus = {PLUGINLIST(hitindx).status}; + for i =1:length(pluginstatus) + if strcmp(pluginstatus{i}, 'ok') + status(i) = 1; + else + status(i) = 0; + end + end + pluginnameout = {PLUGINLIST(hitindx).plugin}; + pluginstruct = PLUGINLIST(hitindx); + end +end diff --git a/functions/adminfunc/plugin_uifilter.m b/functions/adminfunc/plugin_uifilter.m new file mode 100644 index 000000000..a4a0535f2 --- /dev/null +++ b/functions/adminfunc/plugin_uifilter.m @@ -0,0 +1,68 @@ +% PLUGIN_UIFILTER - support function for plugin_menu + +% Copyright (C) 2019 Arnaud Delorme +% +% 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 plugin_uifilter(fig) + +tmpobj = get(fig, 'userdata'); +allPlugins = tmpobj.allplugins; + +filterInstall = get(findobj(fig, 'tag', 'filter1'), 'value'); + +filterVal = get(findobj(fig, 'tag', 'filter2'), 'value'); +filterStr = get(findobj(fig, 'tag', 'filter2'), 'string'); +filterStr = filterStr{filterVal}; + +if filterVal == 1 + selectedPlugins = allPlugins; +else + spaceInd = find(filterStr == ' '); + filterStr = filterStr(spaceInd(2)+1:end); + + % find plugins + pluginList = []; + for iPlugin = 1:length(allPlugins) + if ~isempty(strmatch(filterStr, allPlugins(iPlugin).tags, 'exact')) + pluginList = [ pluginList iPlugin ]; + end + end + selectedPlugins = allPlugins(pluginList); +end + +if filterInstall == 2 + selectedPlugins( [selectedPlugins.installed] == 0) = []; +elseif filterInstall == 3 + selectedPlugins( [selectedPlugins.installed] == 1) = []; +end + +% update GUI +set(findobj(fig, 'tag', 'pluginlist'), 'string', { selectedPlugins.text }, 'value', []); +tmpobj.selection = []; +tmpobj.selectedplugins = selectedPlugins; + +set(fig, 'userdata', tmpobj); diff --git a/functions/adminfunc/plugin_uiupdate.m b/functions/adminfunc/plugin_uiupdate.m new file mode 100644 index 000000000..8652e2e16 --- /dev/null +++ b/functions/adminfunc/plugin_uiupdate.m @@ -0,0 +1,90 @@ +% PLUGUIN_UIUPDATE - support function for plugin_menu + +% Copyright (C) 2019 Arnaud Delorme +% +% 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 plugin_uiupdate(fig) + +tmpobj = get(fig, 'userdata'); +listboxVal = get(findobj(fig, 'tag', 'pluginlist'), 'value'); + +allPlugins = tmpobj.allplugins; +selectedPlugins = tmpobj.selectedplugins; +selection = tmpobj.selection; +if length(listboxVal) == 1 + lastSelect = listboxVal; +else + lastSelect = setdiff(listboxVal, selection); + + % check if selection is consistent + if ~all([selectedPlugins([ listboxVal ]).installed]) && ~all(~[selectedPlugins([ listboxVal ]).installed] ) + listboxVal = lastSelect(1); + set(findobj(fig, 'tag', 'pluginlist'), 'value', listboxVal); + end +end +if isempty(lastSelect), lastSelect = listboxVal(1); end +if length(lastSelect) > 1, lastSelect = lastSelect(1); end + +tmpstr = selectedPlugins(lastSelect).description; + +% set text +hDescription = findobj(fig, 'tag', 'description'); +hTags = findobj(fig, 'tag', 'tags'); +hStatus = findobj(fig, 'tag', 'status'); +hSize = findobj(fig, 'tag', 'size'); +tmpstr = textwrap(hDescription, {tmpstr}); +set(hDescription, 'string', tmpstr); +set(hTags , 'string', selectedPlugins(lastSelect).rawtags ); +set(hSize , 'string', [num2str(ceil(selectedPlugins(lastSelect).size/100)/10) ' MB'] ); + +% installed status +if selectedPlugins(lastSelect).installed + if selectedPlugins(lastSelect).installorupdate + set(hStatus, 'string', ['version ' selectedPlugins(lastSelect).currentversion ' installed - an update is available'] ); + else + set(hStatus , 'string', 'installed' ); + end +else + set(hStatus, 'string', 'not installed'); +end + +% set buttons +set(findobj(fig, 'tag', 'install'), 'enable', 'on'); +if selectedPlugins(lastSelect).installed + set(findobj(fig, 'tag', 'rmbut'), 'enable', 'on'); +else + set(findobj(fig, 'tag', 'rmbut'), 'enable', 'off'); +end +if ~isempty(selectedPlugins(lastSelect).webdoc) + set(findobj(fig, 'tag', 'documentation'), 'enable', 'on', 'callback', ['web(''' selectedPlugins(lastSelect).webdoc ''', ''-browser'');' ]); +else + set(findobj(fig, 'tag', 'documentation'), 'enable', 'off') +end +set(findobj(fig, 'tag', 'rating'), 'callback', ['web(''' selectedPlugins(lastSelect).webrating ''', ''-browser'');' ]); + +tmpobj.selection = listboxVal; +set(fig, 'userdata', tmpobj); diff --git a/functions/adminfunc/plugin_urlread.m b/functions/adminfunc/plugin_urlread.m index e21d13bef..7c4ddd6ed 100644 --- a/functions/adminfunc/plugin_urlread.m +++ b/functions/adminfunc/plugin_urlread.m @@ -1,4 +1,4 @@ -function [output,status] = urlread(urlChar,method,params) +function [output,status] = plugin_urlread(urlChar,method,params) %URLREAD Returns the contents of a URL as a string. % S = URLREAD('URL') reads the content at a URL into a string, S. If the % server returns binary data, the string will contain garbage. @@ -19,6 +19,7 @@ % % See also URLWRITE. +% Adapted by A. Delorme from % Matthew J. Simoneau, 13-Nov-2001 % Copyright 1984-2011 The MathWorks, Inc. % $Revision: 1.3.2.12 $ $Date: 2011/09/03 22:43:00 $ @@ -28,10 +29,14 @@ error(message('MATLAB:urlread:NoJvm')); end -import com.mathworks.mlwidgets.io.InterruptibleStreamCopier; +if exist('OCTAVE_VERSION', 'builtin') == 0 + import com.mathworks.mlwidgets.io.InterruptibleStreamCopier; + + % Be sure the proxy settings are set. + com.mathworks.mlwidgets.html.HTMLPrefs.setProxySettings +end + -% Be sure the proxy settings are set. -com.mathworks.mlwidgets.html.HTMLPrefs.setProxySettings % Check number of inputs and outputs. if ~ischar(urlChar) diff --git a/functions/adminfunc/plugin_urlreadwrite.m b/functions/adminfunc/plugin_urlreadwrite.m index 93a4569bb..ea99b236f 100644 --- a/functions/adminfunc/plugin_urlreadwrite.m +++ b/functions/adminfunc/plugin_urlreadwrite.m @@ -1,6 +1,7 @@ -function [urlConnection,errorid,errormsg] = urlreadwrite(fcn,urlChar) +function [urlConnection,errorid,errormsg] = plugin_urlreadwrite(fcn,urlChar) %URLREADWRITE A helper function for URLREAD and URLWRITE. +% Adapted by A. Delorme from % Matthew J. Simoneau, June 2005 % Copyright 1984-2011 The MathWorks, Inc. % $Revision: 1.1.6.7 $ $Date: 2011/10/22 22:05:21 $ @@ -31,12 +32,56 @@ handler = []; end +%Try to fix proxy +useNewProxyInfo = 0; +try + if exist('OCTAVE_VERSION', 'builtin') == 0 + [matlabversion matlabdate] = version; + matlabversion2 = regexp(matlabversion,'R20(\d\d)([abcd])','match'); + if ~isempty(matlabversion2) + matlabyear = regexp(matlabversion2,'20(\d\d)','match'); + if ~isempty(matlabyear) + matlabyear = str2double(matlabyear{1,1}); + %matlabsubversion = regexp(matlabversion2,strcat(num2str(matlabyear), "([abcd])"),'match','once'); + useNewProxyInfo = matlabyear>=2018; + end + end + end +catch + warning('An error occurred when checking MATLAB/Octave version'); +end + +try + if useNewProxyInfo == 1 + s = settings; + proxyHost = s.matlab.web.ProxyHost.ActiveValue; + proxyPort = s.matlab.web.ProxyPort.ActiveValue; + switch protocol + case 'http' + java.lang.System.setProperty('http.proxyHost',proxyHost); + java.lang.System.setProperty('http.proxyPort',proxyPort); + case 'https' + s = settings; + proxyHost = s.matlab.web.ProxyHost.ActiveValue; + proxyPort = s.matlab.web.ProxyPort.ActiveValue; + java.lang.System.setProperty('https.proxyHost',proxyHost); + java.lang.System.setProperty('https.proxyPort',proxyPort); + otherwise + warning('Unknown web protocol'); + end + end +catch + warning('An error occurred when checking proxy information using new format'); +end + % Create the URL object. try if isempty(handler) url = java.net.URL(urlChar); + % url = javaObject('java.net.URL', urlChar); % Octave else url = java.net.URL([],urlChar,handler); + % url = javaObject('java.net.URL', [],urlChar,handler); % Octave end catch exception %#ok errorid = ['MATLAB:' fcn ':InvalidUrl']; diff --git a/functions/adminfunc/plugin_urlsize.m b/functions/adminfunc/plugin_urlsize.m index 28f4a53f6..f8cb46182 100644 --- a/functions/adminfunc/plugin_urlsize.m +++ b/functions/adminfunc/plugin_urlsize.m @@ -19,6 +19,7 @@ % % See also URLWRITE. +% Adapted by A. Delorme from % Matthew J. Simoneau, 13-Nov-2001 % Copyright 1984-2011 The MathWorks, Inc. % $Revision: 1.3.2.12 $ $Date: 2011/09/03 22:43:00 $ diff --git a/functions/adminfunc/plugin_urlwrite.m b/functions/adminfunc/plugin_urlwrite.m index a20f0be33..6518c6953 100644 --- a/functions/adminfunc/plugin_urlwrite.m +++ b/functions/adminfunc/plugin_urlwrite.m @@ -1,5 +1,5 @@ -function [output,status] = urlwrite(urlChar,location,method,params) -%URLWRITE Save the contents of a URL to a file. +function [output,status] = plugin_urlwrite(urlChar,location,method,params) +% URLWRITE Save the contents of a URL to a file. % URLWRITE(URL,FILENAME) saves the contents of a URL to a file. FILENAME % can specify the complete path to a file. If it is just the name, it will % be created in the current directory. @@ -21,6 +21,7 @@ % % See also URLREAD. +% Adapted by A. Delorme from % Matthew J. Simoneau, 13-Nov-2001 % Copyright 1984-2011 The MathWorks, Inc. % $Revision: 1.4.4.14 $ $Date: 2011/09/03 22:43:01 $ @@ -143,4 +144,4 @@ end end -status = 1; \ No newline at end of file +status = 1; diff --git a/functions/adminfunc/pop_delset.m b/functions/adminfunc/pop_delset.m index 96e6564ef..29168a5ce 100644 --- a/functions/adminfunc/pop_delset.m +++ b/functions/adminfunc/pop_delset.m @@ -1,4 +1,4 @@ -% pop_delset() - Delete a dataset from the variable containing +% POP_DELSET - Delete a dataset from the variable containing % all datasets. % % Usage: >> ALLEEG = pop_delset(ALLEEG, indices); @@ -11,23 +11,34 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % -% See also: pop_copyset(), eeglab() +% See also: POP_COPYSET, EEGLAB % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % load a set and store it in the current set % ------------------------------------------ @@ -37,13 +48,12 @@ if nargin < 1 help pop_delset; return; -end; -if isempty( ALLSET ) - error('Cannot delete dataset. Restart eeglab to clear all dataset information'); - return; -end; +end +if length( ALLSET ) < 2 + error( [ 'Cannot delete dataset when there is only one of them. Restart EEGLAB' 10 'or use the menu item in the File menu to clear all datasets' ]); +end -if nargin < 2 | set_in < 0 +if nargin < 2 || (length(set_in)==1 && set_in < 0) % which set to delete % ----------------- promptstr = { 'Dataset(s) to delete:' }; @@ -51,16 +61,16 @@ inistr = { int2str(-set_in) }; else inistr = { '1' }; - end; + end result = inputdlg2( promptstr, 'Delete dataset -- pop_delset()', 1, inistr, 'pop_delset'); size_result = size( result ); - if size_result(1) == 0 return; end; + if size_result(1) == 0 return; end set_in = eval( [ '[' result{1} ']' ] ); -end; +end if isempty(set_in) return; -end; +end A = fieldnames( ALLSET ); A(:,2) = cell(size(A)); @@ -72,8 +82,9 @@ catch error('Error: no such dataset'); return; - end; -end; + end +end -command = sprintf('%s = pop_delset( %s, [%s] );', inputname(1), inputname(1), int2str(set_in)); +% command = sprintf('%s = pop_delset( %s, [%s] );', inputname(1), inputname(1), int2str(set_in)); +command = sprintf('EEG = pop_delset( EEG, [%s] );', int2str(set_in)); return; diff --git a/functions/adminfunc/pop_editoptions.m b/functions/adminfunc/pop_editoptions.m index 20fa1819b..ccb93e939 100644 --- a/functions/adminfunc/pop_editoptions.m +++ b/functions/adminfunc/pop_editoptions.m @@ -1,4 +1,4 @@ -% pop_editoptions() - Edit memory-saving eeglab() options. These are stored in +% POP_EDITOPTIONS - Edit memory-saving EEGLAB options. These are stored in % a file 'eeg_options.m'. With no argument, pop up a window % to allow the user to set/unset these options. Store % user choices in a new 'eeg_options.m' file in the @@ -10,7 +10,7 @@ % Graphic interface inputs: % "If set, keep at most one dataset in memory ..." - [checkbox] If set, EEGLAB will only retain the current % dataset in memory. All other datasets will be automatically -% read and writen to disk. All EEGLAB functionalities are preserved +% read and written to disk. All EEGLAB functionalities are preserved % even for dataset stored on disk. % "If set, write data in same file as dataset ..." - [checkbox] Set -> dataset data (EEG.data) are % saved in the EEG structure in the standard Matlab dataset (.set) file. @@ -27,7 +27,7 @@ % time courses are precomputed (this requires more RAM). % Command line equivalent: option_computeica. % "If set, remember old folder when reading dataset" - [checkbox] this option -% is convinient if the file you are working on are not in the +% is convenient if the file you are working on are not in the % current folder. % % Commandline keywords: @@ -45,60 +45,73 @@ % and 'option_savematlab' are updated, and a new 'eeg_options.m' file may be % written to the working directory. The copy of 'eeg_options.m' placed in your % working directory overwrites system defaults whenever EEGLAB operates in this -% directory (assuming your working directory is in your MATLABPATH - see path()). +% directory (assuming your working directory is in your MATLABPATH - see PATH). % To adjust these options system-wide, edit the master "eeg_options.m" file in the -% EEGLAB directory heirarchy. +% EEGLAB directory hierarchy. % % Author: Arnaud Delorme, SCCN / INC / UCSD, March 2002 % -% See also: eeg_options(), eeg_readoptions() +% See also: EEG_OPTIONS, EEG_READOPTIONS % Copyright (C) Arnaud Delorme, CNL / Salk Institute, 09 March 2002, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 com = pop_editoptions(varargin); +function com = pop_editoptions(varargin) com = ''; +argsoutput = {}; datasets_in_memory = 0; if nargin > 0 - if ~isstr(varargin{1}) + if ~ischar(varargin{1}) datasets_in_memory = varargin{1}; varargin = {}; - end; -end; + end +end % parse the eeg_options file % ---------------------------- eeglab_options; -if iseeglabdeployed - filename = fullfile(eeglabexefolder,'eeg_options.txt'); - eegoptionbackup = fullfile(eeglabexefolder,'eeg_optionsbackup.txt'); +if isdeployed || (exist('ismcc') && ismcc) + filename = which('eeg_options.txt'); + eegoptionbackup = which('eeg_optionsbackup.txt'); else % folder for eeg_options file (also update the eeglab_options) if ~isempty(EEGOPTION_PATH) homefolder = EEGOPTION_PATH; elseif ispc - if ~exist('evalc'), eval('evalc = @(x)(eval(x));'); end; + if ~exist('evalc'), eval('evalc = @(x)(eval(x));'); end homefolder = deblank(evalc('!echo %USERPROFILE%')); else homefolder = '~'; - end; + end filename = fullfile(homefolder, 'eeg_options.m'); eegoptionbackup = which('eeg_optionsbackup.m'); -end; +end + fid = fopen( filename, 'r+'); % existing file storelocal = 0; if fid == -1 @@ -107,23 +120,53 @@ fid = fopen( fullfile(filepath, filename), 'w'); % new file possible? if fid == -1 error([ 'Cannot write into HOME folder: ' homefolder 10 'You may specify another folder for the eeg_option.m' 10 'file by editing the icadefs.m file' ]); - end; + end fclose(fid); delete(fullfile(filepath, filename)); % read variables values and description % -------------------------------------- - [ header opt ] = eeg_readoptions( eegoptionbackup ); + [ header, opt ] = eeg_readoptions( eegoptionbackup ); else - [filepath filename ext] = fileparts(filename); + [filepath, filename, ext] = fileparts(filename); filename = [ filename ext ]; fprintf('Using option file in directory %s\n', filepath); % read variables values and description % -------------------------------------- - [ header opt ] = eeg_readoptions( eegoptionbackup ); - [ header opt ] = eeg_readoptions( fid, opt ); % use opt from above as default -end; + [ header, opt ] = eeg_readoptions( eegoptionbackup ); + [ header, opt ] = eeg_readoptions( fid, opt ); % use opt from above as default +end + +optionsToShow = { + 'option_storedisk' ... + 'option_savetwofiles' ... + 'option_parallel' ... + 'option_computeica' ... + 'option_rememberfolder' ... + 'option_allmenus' ... + 'option_checkversion' ... + 'option_showadvanced' ... + 'option_boundary99' ... + 'option_cachesize' }; + +% remove advanced options if necessary +if isempty(varargin) + if ~option_showadvanced + % remove options + for iOpt = length(opt):-1:1 + if ~isempty(opt(iOpt).varname) && ~ismember(opt(iOpt).varname, optionsToShow) + opt(iOpt) = []; + end + end + % remove header not serving any option + for iOpt = length(opt)-1:-1:1 + if isempty(opt(iOpt).varname) && isempty(opt(iOpt+1).varname) + opt(iOpt) = []; + end + end + end +end if nargin < 2 geometry = { [6 1] }; @@ -153,41 +196,43 @@ % create the gui for this variable % -------------------------------- - geometry = { geometry{:} [4 0.3 0.1] }; - if strcmpi(opt(index).varname, 'option_storedisk') & datasets_in_memory + if strcmpi(opt(index).varname, 'option_storedisk') && datasets_in_memory cb_nomodif = [ 'set(gcbo, ''value'', ~get(gcbo, ''value''));' ... 'warndlg2(strvcat(''This option may only be modified when at most one dataset is stored in memory.''));' ]; elseif strcmpi(opt(index).varname, 'option_memmapdata') cb_nomodif = [ 'if get(gcbo, ''value''), warndlg2(strvcat(''Matlab memory is beta, use at your own risk'')); end;' ]; + elseif strcmpi(opt(index).varname, 'option_boundary99') + cb_nomodif = [ 'warndlg2(strvcat(''This function is for ERPLAB compatility. If you do not have numerical events,'', ''it will have no effect. If you have numerical events, type -99 will be used as boundary'', ''event type throughout EEGLAB. If you use this option to process some datasets and then'', ''unset it, EEGLAB will no longer detect type -99 boundaries, so be careful!'' ));' ]; elseif strcmpi(opt(index).varname, 'option_donotusetoolboxes') cb_nomodif = [ 'if get(gcbo, ''value''), warndlg2([''You have selected the option to disable'' 10 ''Matlab toolboxes. Use with caution.'' 10 ''Matlab toolboxes will be removed from'' 10 ''your path. Unlicking this option later will not'' 10 ''add back the toolboxes. You will need'' 10 ''to add them back manually. If you are unsure'' 10 ''if you want to disable Matlab toolboxes'' 10 ''deselect the option now.'' ]); end;' ]; else cb_nomodif = ''; - end; + end if ~isempty(opt(index).value) - uilist = { uilist{:}, { 'Style', 'text', descrip{:}, 'horizontalalignment', 'left' }, ... - { 'Style', 'checkbox', 'string', ' ', 'value', opt(index).value 'callback' cb_nomodif } { } }; + if opt(index).value <= 1 + uilist = { uilist{:}, { 'Style', 'text', descrip{:}, 'horizontalalignment', 'left' }, ... + { 'Style', 'checkbox', 'string', ' ', 'value', opt(index).value 'callback' cb_nomodif } { } }; + geometry = { geometry{:} [4 0.3 0.1] }; + else + uilist = { uilist{:}, { 'Style', 'text', descrip{:}, 'horizontalalignment', 'left' }, ... + { 'Style', 'edit', 'string', num2str(opt(index).value), 'callback' cb_nomodif } { } }; + geometry = { geometry{:} [3 0.5 0.1] }; + end else - uilist = { uilist{:}, { 'Style', 'text', descrip{:}, 'fontweight' 'bold', 'horizontalalignment', 'left' }, ... - { } { } }; - end; - end; + uilist = { uilist{:}, { 'Style', 'text', descrip{:}, 'fontweight' 'bold', 'horizontalalignment', 'left' }, { } { } }; + geometry = { geometry{:} [4 0.3 0.1] }; + end + end % change option file uilist = { uilist{:} {} ... - { 'Style', 'text', 'string', 'Option file:' 'fontweight', 'bold' }, ... - { 'Style', 'text', 'string', tmpfile 'tag' 'filename' }, ... - {} { 'Style', 'pushbutton', 'string', '...' 'callback' cb_file } }; - geometry = { geometry{:} [1] [1 6 0.1 0.8] }; - [results userdat ] = inputgui( geometry, uilist, 'pophelp(''pop_editoptions'');', 'Memory options - pop_editoptions()', ... + { 'Style', 'text', 'string', 'Edit the EEGOPTION_PATH variable of functions/sigprocfunc/icadefs.m to change where the option file is saved' } }; + geometry = { geometry{:} [1] [1] }; + [results, userdat ] = inputgui( geometry, uilist, 'pophelp(''pop_editoptions'');', 'Memory options - pop_editoptions()', ... [], 'normal'); - if ~isempty(userdat) - filepath = fileparts(userdat); - args = { 'filename' filename }; - end; - if length(results) == 0, return; end; + if isempty(results), return; end % decode inputs % ------------- @@ -197,15 +242,14 @@ if ~isempty(opt(index).varname) args = { args{:}, opt(index).varname, results{count} }; count = count+1; - end; - end; + end + end else % no interactive inputs % --------------------- args = varargin; -end; +end - % change default folder option % ---------------------------- W_MAIN = findobj('tag', 'EEGLAB'); @@ -213,24 +257,33 @@ tmpuserdata = get(W_MAIN, 'userdata'); tmpuserdata{3} = filepath; set(W_MAIN, 'userdata', tmpuserdata); -end; - +end + % decode inputs % ------------- for index = 1:2:length(args) ind = strmatch(args{index}, { opt.varname }, 'exact'); if isempty(ind) if strcmpi(args{index}, 'option_savematlab') - disp('pop_editoptions: option_savematlab is obsolete, use option_savetwofiles instead'); + disp('pop_editoptions: option_savematlab is obsolete, use option_savetwofiles instead'); ind = strmatch('option_savetwofiles', { opt.varname }, 'exact'); - opt(ind).value = ~args{index+1}; else error(['Variable name ''' args{index} ''' is invalid']); - end; - else - opt(ind).value = args{index+1}; - end; -end; + end + end + + % case for 'option_cachesize' + if strcmpi(args{index}, 'option_cachesize') && ischar(args{index+1}) + args{index+1} = str2num(args{index+1}); + end + + % overwrite only if different + if args{index+1} ~= opt(ind).value + opt(ind).value = args{index+1}; + argsoutput{end+1} = args{index}; % for history + argsoutput{end+1} = args{index+1}; % for history + end +end % write to eeg_options file % ------------------------- @@ -238,37 +291,44 @@ addpath(filepath); if fid == -1 error('File writing error, check writing permission'); -end; +end fprintf(fid, '%s\n', header); for index = 1:length(opt) if isempty(opt(index).varname) fprintf( fid, '%% %s\n', opt(index).description); else fprintf( fid, '%s = %d ; %% %s\n', opt(index).varname, opt(index).value, opt(index).description); - end; -end; + end +end fclose(fid); % clear it from the MATLAB function cache clear(fullfile(filepath,filename)); % generate the output text command % -------------------------------- -com = 'pop_editoptions('; -for index = 1:2:length(args) - com = sprintf( '%s ''%s'', %d,', com, args{index}, args{index+1}); -end; -com = [com(1:end-1) ');']; +if ~isempty(argsoutput) + com = 'pop_editoptions('; + for index = 1:2:length(argsoutput) + com = sprintf( '%s ''%s'', %d,', com, argsoutput{index}, argsoutput{index+1}); + end + com = [com(1:end-1) ');']; +else + disp('pop_editoptions: Options were not modified'); +end +wtmp = warning; +warning off; clear functions +warning(wtmp); % --------------------------- function chopedtext = choptext( tmptext ) chopedtext = ''; while length(tmptext) > 30 blanks = findstr( tmptext, ' '); - [tmp I] = min( abs(blanks - 30) ); + [tmp, I] = min( abs(blanks - 30) ); chopedtext = [ chopedtext ''' 10 ''' tmptext(1:blanks(I)) ]; tmptext = tmptext(blanks(I)+1:end); - end; + end chopedtext = [ chopedtext ''' 10 ''' tmptext]; chopedtext = chopedtext(7:end); return; @@ -276,7 +336,7 @@ function num = popask( text ) ButtonName=questdlg2( text, ... 'Confirmation', 'Cancel', 'Yes','Yes'); - switch lower(ButtonName), + switch lower(ButtonName) case 'cancel', num = 0; case 'yes', num = 1; - end; + end diff --git a/functions/adminfunc/pop_rejmenu.m b/functions/adminfunc/pop_rejmenu.m index b3f5bc7e0..25ce88c6b 100644 --- a/functions/adminfunc/pop_rejmenu.m +++ b/functions/adminfunc/pop_rejmenu.m @@ -1,4 +1,4 @@ -% pop_rejmenu() - Main menu for rejecting trials in an EEG dataset +% POP_REJMENU - Main menu for rejecting trials in an EEG dataset % % Usage: >> pop_rejmenu(INEEG, typerej); % @@ -9,32 +9,43 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % -% See also: eeglab(), pop_eegplot(), pop_eegthresh, pop_rejtrend() -% pop_rejkurt(), pop_jointprob(), pop_rejspec() +% See also: EEGLAB, POP_EEGPLOT, pop_eegthresh, POP_REJTREND +% POP_REJKURT, POP_JOINTPROB, POP_REJSPEC % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 pop_rejmenu( EEG, icacomp ); if icacomp == 0 if isempty( EEG.icasphere ) disp('Error: you must first run ICA on the data'); return; - end; -end; + end +end if icacomp == 1 rejtitle = 'Reject trials using data statistics - pop_rejmenu()'; tagmenu = 'rejtrialraw'; else rejtitle = 'Reject trials using component activity statistics - pop_rejmenu()'; tagmenu = 'rejtrialica'; @@ -42,7 +53,7 @@ if ~isempty( findobj('tag', tagmenu)) error('cannot open two identical windows; close the first one first'); -end; +end figure('visible', 'off', 'numbertitle', 'off', 'name', rejtitle, 'tag', tagmenu); @@ -62,7 +73,7 @@ if icacomp, ICAPREFIX = ''; else ICAPREFIX = 'ica'; -end; +end % tmp_comall is used when returning from eegplot tmp_comall = [ 'set(findobj(''''parent'''', findobj(''''tag'''', ''''' tagmenu ... '''''), ''''tag'''', ''''mantrial''''), ''''string'''', num2str(sum(EEG.reject.' ICAPREFIX 'rejmanual)));' ... @@ -180,7 +191,7 @@ 'end;' ]; cb_clear = [ 'close gcbf; EEG = rmfield( EEG, ''reject''); EEG.reject.rejmanual = [];' ... - 'EEG=eeg_checkset(EEG); pop_rejmenu(' inputname(1) ',' int2str(icacomp) ');' ]; + 'EEG=eeg_checkset(EEG); pop_rejmenu(EEG,' int2str(icacomp) ');' ]; cb_close = [ 'close gcbf;' ... 'disp(''Marks stored in dataset'');' ... @@ -208,18 +219,18 @@ sizekurt = 0; sizespec = 0; if icacomp == 1 - if ~isempty(EEG.reject.rejmanual), sizeman = length(find(EEG.reject.rejmanual)); end; - if ~isempty(EEG.reject.rejconst), sizetrend = length(find(EEG.reject.rejconst)); end; - if ~isempty(EEG.reject.rejjp), sizejp = length(find(EEG.reject.rejjp)); end; - if ~isempty(EEG.reject.rejkurt), sizekurt = length(find(EEG.reject.rejkurt)); end; - if ~isempty(EEG.reject.rejfreq), sizespec = length(find(EEG.reject.rejfreq)); end; + if ~isempty(EEG.reject.rejmanual), sizeman = length(find(EEG.reject.rejmanual)); end + if ~isempty(EEG.reject.rejconst), sizetrend = length(find(EEG.reject.rejconst)); end + if ~isempty(EEG.reject.rejjp), sizejp = length(find(EEG.reject.rejjp)); end + if ~isempty(EEG.reject.rejkurt), sizekurt = length(find(EEG.reject.rejkurt)); end + if ~isempty(EEG.reject.rejfreq), sizespec = length(find(EEG.reject.rejfreq)); end else - if ~isempty(EEG.reject.icarejmanual), sizeman = length(find(EEG.reject.icarejmanual)); end; - if ~isempty(EEG.reject.icarejconst), sizetrend = length(find(EEG.reject.icarejconst)); end; - if ~isempty(EEG.reject.icarejjp), sizejp = length(find(EEG.reject.icarejjp)); end; - if ~isempty(EEG.reject.icarejkurt), sizekurt = length(find(EEG.reject.icarejkurt)); end; + if ~isempty(EEG.reject.icarejmanual), sizeman = length(find(EEG.reject.icarejmanual)); end + if ~isempty(EEG.reject.icarejconst), sizetrend = length(find(EEG.reject.icarejconst)); end + if ~isempty(EEG.reject.icarejjp), sizejp = length(find(EEG.reject.icarejjp)); end + if ~isempty(EEG.reject.icarejkurt), sizekurt = length(find(EEG.reject.icarejkurt)); end if ~isempty(EEG.reject.icarejfreq), sizespec = length(find(EEG.reject.icarejfreq)); end; - end; + end stdl = [0.25 1.2 0.8 1.2 0.8]; % standard line titl = [0.9 0.18 1.55]; % title line diff --git a/functions/adminfunc/pop_stdwarn.m b/functions/adminfunc/pop_stdwarn.m index 16bf3c34e..a2a5889d2 100644 --- a/functions/adminfunc/pop_stdwarn.m +++ b/functions/adminfunc/pop_stdwarn.m @@ -1,26 +1,37 @@ -% pop_stdwarn() - check memory options and issue warning for studies. +% POP_STDWARN - check memory options and issue warning for studies. % % Usage: >> pop_stdwarn; % % Author: Arnaud Delorme, CERCO, 2007 % -% See also: eeg_options() +% See also: EEG_OPTIONS % Copyright (C) Arnaud Delorme, CERCO, 2007, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. res = 0; @@ -35,5 +46,5 @@ 'contain the EEG data.', ' '); res = questdlg2(vartext, 'Study warning', 'Cancel', 'Ok', 'Ok'); - if strcmpi(res, 'Cancel'),return; end; -end; + if strcmpi(res, 'Cancel'),return; end +end diff --git a/functions/adminfunc/removepath.m b/functions/adminfunc/removepath.m new file mode 100644 index 000000000..ef132177c --- /dev/null +++ b/functions/adminfunc/removepath.m @@ -0,0 +1,44 @@ +% remove all path with a given parent path +% varargin contains a list of path to exclude + +% Copyright (C) 2006 Arnaud Delorme +% +% 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 removepath(parentpath, varargin) + +if isempty(parentpath), return; end +folder = path; +if ispc, sep = ';'; else sep = ':'; end +indSep = find(folder == sep); + +indSep = [ 0 indSep length(folder)+1 ]; +for iSep = 1:length(indSep)-1 + curPath = folder(indSep(iSep)+1:indSep(iSep+1)-1); + if ~isempty(strfind(curPath, parentpath)) && ~any(strmatch(curPath, varargin, 'exact')) + rmpath(curPath); + end +end diff --git a/functions/adminfunc/search-icon.png b/functions/adminfunc/search-icon.png new file mode 100644 index 000000000..435d74cb8 Binary files /dev/null and b/functions/adminfunc/search-icon.png differ diff --git a/functions/adminfunc/setdiff_bc.m b/functions/adminfunc/setdiff_bc.m index dc80d4b7e..ded42e8d1 100644 --- a/functions/adminfunc/setdiff_bc.m +++ b/functions/adminfunc/setdiff_bc.m @@ -1,20 +1,47 @@ % setdiff_bc - setdiff backward compatible with Matlab versions prior to 2013a -function [C,IA] = setdiff_bc(A,B,varargin); +% Copyright (C) 2013 Arnaud Delorme +% +% 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 [C,IA] = setdiff_bc(A,B,varargin) errorFlag = error_bc; v = version; indp = find(v == '.'); v = str2num(v(1:indp(2)-1)); -if v > 7.19, v = floor(v) + rem(v,1)/10; end; +if v > 7.19, v = floor(v) + rem(v,1)/10; end if nargin > 2 ind = strmatch('legacy', varargin); if ~isempty(ind) varargin(ind) = []; - end; -end; + end +end if v >= 7.14 [C,IA] = setdiff(A,B,varargin{:},'legacy'); @@ -22,8 +49,8 @@ [C2,IA2] = setdiff(A,B,varargin{:}); if (~isequal(C, C2) || ~isequal(IA, IA2)) warning('backward compatibility issue with call to setdiff function'); - end; - end; + end + end else [C,IA] = setdiff(A,B,varargin{:}); -end; \ No newline at end of file +end diff --git a/functions/adminfunc/troubleshooting_data_formats.m b/functions/adminfunc/troubleshooting_data_formats.m index 1be982471..78f2958d4 100644 --- a/functions/adminfunc/troubleshooting_data_formats.m +++ b/functions/adminfunc/troubleshooting_data_formats.m @@ -1,16 +1,16 @@ %Several EEGLAB plugins (not included by default) are available to import %specific data formats. To download these plugins use EEGLAB menu % -%File > Manage Plugins > Manage data import plugins +%File > Manage EEGLAB extensions % %The FILEIO and BIOSIG toolboxes interface also allow to import in EEGLAB a wide variety %of EEG/MEG data file formats -- including those imported using EEGLAB native menus % -%For EEGLAB, FILE-IO and BIOSIG suported data formats +%For EEGLAB, FILEIO and BIOSIG supported data formats %http://sccn.ucsd.edu/wiki/A01:_Importing_Continuous_and_Epoched_Data % -%For FILE-IO see in addition -%http://www2.ru.nl/fcdonders/fieldtrip/doku.php?id=fieldtrip:dataformat +%For FILEIO see in addition +%http://www.fieldtriptoolbox.org/development/fileio % %For BIOSIG see in addition %http://biosig.sourceforge.net/SupportedSystems.html diff --git a/functions/adminfunc/union_bc.m b/functions/adminfunc/union_bc.m index 5be4154bd..a307b3ba1 100644 --- a/functions/adminfunc/union_bc.m +++ b/functions/adminfunc/union_bc.m @@ -1,20 +1,47 @@ % union_bc - union backward compatible with Matlab versions prior to 2013a -function [C,IA,IB] = union_bc(A,B,varargin); +% Copyright (C) 2013 Arnaud Delorme +% +% 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 [C,IA,IB] = union_bc(A,B,varargin) errorFlag = error_bc; v = version; indp = find(v == '.'); v = str2num(v(1:indp(2)-1)); -if v > 7.19, v = floor(v) + rem(v,1)/10; end; +if v > 7.19, v = floor(v) + rem(v,1)/10; end if nargin > 2 ind = strmatch('legacy', varargin); if ~isempty(ind) varargin(ind) = []; - end; -end; + end +end if v >= 7.14 [C,IA,IB] = union(A,B,varargin{:},'legacy'); @@ -22,8 +49,8 @@ [C2,IA2,IB2] = union(A,B,varargin{:}); if (~isequal(C, C2) || ~isequal(IA, IA2) || ~isequal(IB, IB2)) warning('backward compatibility issue with call to union function'); - end; - end; + end + end else [C,IA,IB] = union(A,B,varargin{:}); -end; \ No newline at end of file +end diff --git a/functions/adminfunc/unique_bc.m b/functions/adminfunc/unique_bc.m index 625655007..e6d1195de 100644 --- a/functions/adminfunc/unique_bc.m +++ b/functions/adminfunc/unique_bc.m @@ -1,20 +1,47 @@ % unique_bc - unique backward compatible with Matlab versions prior to 2013a -function [C,IA,IB] = unique_bc(A,varargin); +% Copyright (C) 2013 Arnaud Delorme +% +% 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 [C,IA,IB] = unique_bc(A,varargin) errorFlag = error_bc; v = version; indp = find(v == '.'); v = str2num(v(1:indp(2)-1)); -if v > 7.19, v = floor(v) + rem(v,1)/10; end; +if v > 7.19, v = floor(v) + rem(v,1)/10; end if nargin > 2 ind = strmatch('legacy', varargin); if ~isempty(ind) varargin(ind) = []; - end; -end; + end +end if v >= 7.14 [C,IA,IB] = unique(A,varargin{:},'legacy'); @@ -22,8 +49,8 @@ [C2,IA2] = unique(A,varargin{:}); if ~isequal(C, C2) || ~isequal(IA, IA2) || ~isequal(IB, IB2) warning('backward compatibility issue with call to unique function'); - end; - end; + end + end else [C,IA,IB] = unique(A,varargin{:}); -end; \ No newline at end of file +end diff --git a/functions/adminfunc/vararg2str.m b/functions/adminfunc/vararg2str.m index 9930703c5..13a7c7d59 100644 --- a/functions/adminfunc/vararg2str.m +++ b/functions/adminfunc/vararg2str.m @@ -1,5 +1,5 @@ -% vararg2str() - transform arguments into string for evaluation -% using the eval() command +% VARARG2STR - transform arguments into string for evaluation +% using the EVAL command % % Usage: % >> strout = vararg2str( allargs ); @@ -22,30 +22,41 @@ % Copyright (C) Arnaud Delorme, CNL / Salk Institute, 9 April 2002 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 strout = vararg2str(allargs, inputnam, inputnum, int2str ); if nargin < 1 help vararg2str; return; -end; +end if isempty(allargs) strout = ''; return; -end; +end % default arguments % ----------------- @@ -54,25 +65,25 @@ else if length(inputnam) < length(allargs) inputnam(end+1:length(allargs)) = {''}; - end; -end; + end +end if nargin < 3 inputnum(1:length(allargs)) = NaN; else if length(inputnum) < length(allargs) inputnum(end+1:length(allargs)) = NaN; - end; -end; + end +end if nargin < 4 int2str(1:length(allargs)) = 0; else if length(int2str) < length(allargs) int2str(end+1:length(allargs)) = 0; - end; -end; + end +end if ~iscell( allargs ) allargs = { allargs }; -end; +end % actual conversion % ----------------- @@ -82,35 +93,37 @@ if ~isempty(inputnam{index}) strout = [ strout ',' inputnam{index} ]; else - if isstr( tmpvar ) + if ischar( tmpvar ) if int2str(index) strout = [ strout ',' tmpvar ]; else strout = [ strout ',' str2str( tmpvar ) ]; - end; - elseif isnumeric( tmpvar ) | islogical( tmpvar ) + end + elseif isnumeric( tmpvar ) || islogical( tmpvar ) strout = [ strout ',' array2str( tmpvar ) ]; elseif iscell( tmpvar ) tmpres = vararg2str( tmpvar ); - comas = find( tmpres == ',' ); - tmpres(comas) = ' '; +% comas = find( tmpres == ',' ); +% tmpres(comas) = ' '; strout = [ strout ',{' tmpres '}' ]; elseif isstruct(tmpvar) strout = [ strout ',' struct2str( tmpvar ) ]; - else + elseif isa(tmpvar, 'function_handle') + strout = [ strout ',' char( tmpvar ) ]; + else error('Unrecognized input'); - end; - end; + end + end -end; +end if ~isempty(strout) strout = strout(2:end); -end; +end % convert string to string % ------------------------ function str = str2str( array ) - if isempty( array), str = ''''''; return; end; + if isempty( array), str = ''''''; return; end str = ''; for index = 1:size(array,1) tmparray = deblank(array(index,:)); @@ -118,8 +131,8 @@ str = [ str ','' ''' ]; else str = [ str ',''' doublequotes(tmparray) '''' ]; - end; - end; + end + end if size(array,1) > 1 str = [ 'strvcat(' str(2:end) ')']; else @@ -130,14 +143,14 @@ % convert array to string % ----------------------- function str = array2str( array ) - if isempty( array), str = '[]'; return; end; - if prod(size(array)) == 1, str = num2str(array); return; end; - if size(array,1) == 1, str = [ '[' contarray(array) '] ' ]; return; end; - if size(array,2) == 1, str = [ '[' contarray(array') ']'' ' ]; return; end; + if isempty( array), str = '[]'; return; end + if prod(size(array)) == 1, str = num2str(array); return; end + if size(array,1) == 1, str = [ '[' contarray(array) '] ' ]; return; end + if size(array,2) == 1, str = [ '[' contarray(array') ']'' ' ]; return; end str = ''; for index = 1:size(array,1) str = [ str ';' contarray(array(index,:)) ]; - end; + end str = [ '[' str(2:end) ']' ]; return; @@ -146,14 +159,14 @@ function str = struct2str( structure ) if isempty( structure ) str = 'struct([])'; return; - end; + end str = ''; allfields = fieldnames( structure ); for index = 1:length( allfields ) strtmp = ''; eval( [ 'allcontent = { structure.' allfields{index} ' };' ] ); % getfield generates a bug str = [ str, '''' allfields{index} ''',{' vararg2str( allcontent ) '},' ]; - end; + end str = [ 'struct(' str(1:end-1) ')' ]; return; @@ -164,8 +177,8 @@ if ~isempty(quoteloc) for index = length(quoteloc):-1:1 str = [ str(1:quoteloc(index)) str(quoteloc(index):end) ]; - end; - end; + end + end return; % test continuous arrays @@ -176,36 +189,36 @@ if prod(size(array)) == 1 str = num2str(array); return; - end; - if size(array,1) == 1 & size(array,2) == 2 + end + if size(array,1) == 1 && size(array,2) == 2 str = [num2str(array(1)) ' ' num2str(array(2))]; return; - end; - if isempty(tmpind) | all(isnan(array(tmpind))) + end + if isempty(tmpind) || all(isnan(array(tmpind))) str = num2str(array(1)); skip = 0; indent = array(2) - array(1); for index = 2:length(array) - if array(index) ~= array(index-1)+indent | indent == 0 + if array(index) ~= array(index-1)+indent || indent == 0 if skip <= 1 if skip == 0 str = [str ' ' num2str(array(index))]; else str = [str ' ' num2str(array(index-1)) ' ' num2str(array(index))]; - end; + end else if indent == 1 str = [str ':' num2str(array(index-1)) ' ' num2str(array(index))]; else str = [str ':' num2str(indent) ':' num2str(array(index-1)) ' ' num2str(array(index))]; - end; - end; + end + end skip = 0; indent = array(index) - array(index-1); else skip = skip + 1; - end; - end; + end + end if array(index) == array(index-1)+indent if skip ~= 0 if indent == 1 @@ -214,17 +227,17 @@ str = [str ' ' num2str(array(index)) ]; else str = [str ':' num2str(indent) ':' num2str(array(index)) ]; - end; - end; - end; + end + end + end else if length(array) < 10 str = num2str(array(1)); for index = 2:length(array) str = [str ' ' num2str(array(index)) ]; - end; + end else str = num2str(double(array)); - end; - end; + end + end diff --git a/functions/guifunc/errordlg2.m b/functions/guifunc/errordlg2.m index ed9e9c197..24a4f44f8 100644 --- a/functions/guifunc/errordlg2.m +++ b/functions/guifunc/errordlg2.m @@ -1,4 +1,4 @@ -% errordlg2() - Makes a popup dialog box with the specified message and (optional) +% ERRORDLG2 - Makes a popup dialog box with the specified message and (optional) % title. % % Usage: @@ -8,28 +8,39 @@ % errordlg2('Explanation of error','title of error'); % % Input: -% Prompt - A text string explaning why the user is seeing this error message. +% Prompt - A text string explaining why the user is seeing this error message. % Title _ A text string that appears in the title bar of the error message. % % Author: Arnaud Delorme, CNL / Salk Institute, 12 August 2002 % -% See also: inputdlg2(), questdlg2() +% See also: INPUTDLG2, QUESTDLG2 % Copyright (C) Arnaud Delorme, CNL / Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 errordlg2(Prompt, Title); @@ -37,9 +48,8 @@ beep; else disp(char(7)); -end; +end if nargin <2 Title = 'Error'; -end; -if ~ismatlab, error(Prompt); end; +end questdlg2(Prompt, Title, 'OK', 'OK'); diff --git a/functions/guifunc/finputcheck.m b/functions/guifunc/finputcheck.m index d2ce131b9..f95123742 100644 --- a/functions/guifunc/finputcheck.m +++ b/functions/guifunc/finputcheck.m @@ -1,4 +1,4 @@ -% finputcheck() - check Matlab function {'key','value'} input argument pairs +% FINPUTCHECK - check Matlab function {'key','value'} input argument pairs % % Usage: >> result = finputcheck( varargin, fieldlist ); % >> [result varargin] = finputcheck( varargin, fieldlist, ... @@ -34,7 +34,7 @@ % { 'title' 'string' [] ''; ... % 'percent' 'real' [0 1] 1 ; ... % 'elecamp' 'integer' [1:10] [] }); -% if isstr(result) +% if ischar(result) % error(result); % end % @@ -49,37 +49,48 @@ % Copyright (C) Arnaud Delorme, CNL / Salk Institute, 10 July 2002, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [g, varargnew] = finputcheck( vararg, fieldlist, callfunc, mode, verbose ) if nargin < 2 help finputcheck; return; - end; + end if nargin < 3 callfunc = ''; else callfunc = [callfunc ' ' ]; - end; + end if nargin < 4 mode = 'do not ignore'; - end; + end if nargin < 5 verbose = 'verbose'; - end; + end NAME = 1; TYPE = 2; VALS = 3; @@ -96,8 +107,8 @@ for index=1:length(vararg) if iscell(vararg{index}) vararg{index} = {vararg{index}}; - end; - end; + end + end try g = struct(vararg{:}); catch @@ -106,19 +117,19 @@ g = struct(vararg{:}); catch g = [ callfunc 'error: bad ''key'', ''val'' sequence' ]; return; - end; - end; - end; + end + end + end else g = []; - end; + end for index = 1:size(fieldlist,NAME) % check if present % ---------------- if ~isfield(g, fieldlist{index, NAME}) g = setfield( g, fieldlist{index, NAME}, fieldlist{index, DEF}); - end; + end tmpval = getfield( g, {1}, fieldlist{index, NAME}); % check type @@ -126,7 +137,7 @@ if ~iscell( fieldlist{index, TYPE} ) res = fieldtest( fieldlist{index, NAME}, fieldlist{index, TYPE}, ... fieldlist{index, VALS}, tmpval, callfunc ); - if isstr(res), g = res; return; end; + if ischar(res), g = res; return; end else testres = 0; tmplist = fieldlist; @@ -136,18 +147,18 @@ fieldlist{index, VALS}, tmpval, callfunc ); else res{it} = fieldtest( fieldlist{index, NAME}, fieldlist{index, TYPE}{it}, ... fieldlist{index, VALS}{it}, tmpval, callfunc ); - end; - if ~isstr(res{it}), testres = 1; end; - end; + end + if ~ischar(res{it}), testres = 1; end + end if testres == 0, g = res{1}; for tmpi = 2:length(res) g = [ g 10 'or ' res{tmpi} ]; - end; + end return; - end; - end; - end; + end + end + end % check if fields are defined % --------------------------- @@ -156,11 +167,11 @@ if isempty(strmatch(allfields{index}, fieldlist(:, 1)', 'exact')) if ~strcmpi(mode, 'ignore') g = [ callfunc 'error: undefined argument ''' allfields{index} '''']; return; - end; + end varargnew{end+1} = allfields{index}; varargnew{end+1} = getfield(g, {1}, allfields{index}); - end; - end; + end + end function g = fieldtest( fieldname, fieldtype, fieldval, tmpval, callfunc ); @@ -175,7 +186,7 @@ case { 'integer' 'real' 'boolean' 'float' }, if ~isnumeric(tmpval) && ~islogical(tmpval) g = [ callfunc 'error: argument ''' fieldname ''' must be numeric' ]; return; - end; + end if strcmpi(fieldtype, 'boolean') if tmpval ~=0 && tmpval ~= 1 g = [ callfunc 'error: argument ''' fieldname ''' must be 0 or 1' ]; return; @@ -186,58 +197,61 @@ if (any(isnan(tmpval(:))) && ~any(isnan(fieldval))) ... && (~ismember(tmpval, fieldval)) g = [ callfunc 'error: wrong value for argument ''' fieldname '''' ]; return; - end; - end; + end + end else % real or float if ~isempty(fieldval) && ~isempty(tmpval) if any(tmpval < fieldval(1)) || any(tmpval > fieldval(2)) g = [ callfunc 'error: value out of range for argument ''' fieldname '''' ]; return; - end; - end; - end; + end + end + end end; case 'string' - if ~isstr(tmpval) + if ~ischar(tmpval) && ~isempty(tmpval) g = [ callfunc 'error: argument ''' fieldname ''' must be a string' ]; return; - end; + end if ~isempty(fieldval) - if isempty(strmatch(lower(tmpval), lower(fieldval), 'exact')) + if isempty(strmatch(char(lower(tmpval)), lower(fieldval), 'exact')) g = [ callfunc 'error: wrong value for argument ''' fieldname '''' ]; return; - end; - end; + end + end case 'cell' if ~iscell(tmpval) g = [ callfunc 'error: argument ''' fieldname ''' must be a cell array' ]; return; - end; + end case 'struct' if ~isstruct(tmpval) g = [ callfunc 'error: argument ''' fieldname ''' must be a structure' ]; return; - end; + end case 'function_handle' if ~isa(tmpval, 'function_handle') g = [ callfunc 'error: argument ''' fieldname ''' must be a function handle' ]; return; - end; + end case ''; otherwise, error([ 'finputcheck error: unrecognized type ''' fieldname '''' ]); - end; + end % remove duplicates in the list of parameters % ------------------------------------------- function cella = removedup(cella, verbose) -% make sure if all the values passed to unique() are strings, if not, exist +% make sure if all the values passed to UNIQUE are strings, if not, exist %try - [tmp indices] = unique_bc(cella(1:2:end)); - if length(tmp) ~= length(cella)/2 - myfprintf(verbose,'Note: duplicate ''key'', ''val'' parameter(s), keeping the last one(s)\n'); - end; + allFields = cella(1:2:end); + [tmp, indices, X] = unique_bc(allFields); + if length(tmp) ~= length(allFields) + Y = hist(X,unique(X)); + fieldDuplicates = allFields(Y > 1); + myfprintf(verbose,'Note: duplicate ''%s'' parameter(s), keeping the last one(s)\n', fieldDuplicates{1}); + end cella = cella(sort(union(indices*2-1, indices*2))); %catch % some elements of cella were not string @@ -248,4 +262,4 @@ function myfprintf(verbose, varargin) if strcmpi(verbose, 'verbose') fprintf(varargin{:}); -end; +end diff --git a/functions/guifunc/inputdlg2.m b/functions/guifunc/inputdlg2.m index c7b588065..bb84e994e 100644 --- a/functions/guifunc/inputdlg2.m +++ b/functions/guifunc/inputdlg2.m @@ -1,13 +1,13 @@ -% inputdlg2() - inputdlg function clone with coloring and help for -% eeglab(). +% INPUTDLG2 - inputdlg function clone with coloring and help for +% EEGLAB. % % Usage: % >> Answer = inputdlg2(Prompt,Title,LineNo,DefAns,funcname); % % Inputs: -% Same as inputdlg. Using the optional additionnal funcname parameter +% Same as inputdlg. Using the optional additional funcname parameter % the function will create a help button. The help message will be -% displayed using the pophelp() function. +% displayed using the POPHELP function. % % Output: % Same as inputdlg @@ -19,37 +19,64 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, La Jolla, 11 August 2002 % -% See also: supergui(), inputgui() +% See also: SUPERGUI, INPUTGUI % Copyright (C) Arnaud Delorme, CNL / Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [result] = inputdlg2(Prompt,Title,LineNo,DefAns,funcname); +function [result] = inputdlg2(Prompt,Title,LineNo,DefAns,funcname) +if nargin < 2 + help inputdlg2; + return; +end +if nargin < 3 + LineNo = 1; +end if nargin < 4 + DefAns = {}; +end +if nargin < 2 help inputdlg2; return; -end; +end if nargin < 5 funcname = ''; -end; +end +if ~iscell(Prompt), Prompt = { Prompt }; end +if isempty(DefAns) + DefAns = cell(1,length(Prompt)); + DefAns(:) = { '' }; +end + if length(Prompt) ~= length(DefAns) - error('inputdlg2: prompt and default answer cell array must have the smae size'); -end; + error('inputdlg2: prompt and default answer cell array must have the same size'); +end geometry = {}; listgui = {}; @@ -59,19 +86,19 @@ geomvert = []; for index = 1:length(Prompt) geomvert = [geomvert size(Prompt{index},1) 1]; % default is vertical geometry -end; -if all(geomvert == 1) & length(Prompt) > 1 +end +if all(geomvert == 1) && length(Prompt) > 1 geomvert = []; % horizontal -end; +end for index = 1:length(Prompt) if ~isempty(geomvert) % vertical geometry = { geometry{:} [ 1] [1 ]}; else geometry = { geometry{:} [ 1 0.6 ]}; - end; + end listgui = { listgui{:} { 'Style', 'text', 'string', Prompt{index}} ... { 'Style', 'edit', 'string', DefAns{index} } }; -end; +end result = inputgui(geometry, listgui, ['pophelp(''' funcname ''');'], Title, [], 'normal', geomvert); diff --git a/functions/guifunc/inputgui.m b/functions/guifunc/inputgui.m index b36d5783c..556219458 100644 --- a/functions/guifunc/inputgui.m +++ b/functions/guifunc/inputgui.m @@ -1,4 +1,4 @@ -% inputgui() - A comprehensive gui automatic builder. This function helps +% INPUTGUI - A comprehensive gui automatic builder. This function helps % to create GUI very quickly without bothering about the % positions of the elements. After creating a geometry, % elements just place themselves in the predefined @@ -7,7 +7,7 @@ % % Usage: % >> [ outparam ] = inputgui( 'key1', 'val1', 'key2', 'val2', ... ); -% >> [ outparam userdat strhalt outstruct] = ... +% >> [ outparam userdat strhalt outstruct tags] = ... % inputgui( 'key1', 'val1', 'key2', 'val2', ... ); % % Inputs: @@ -22,7 +22,7 @@ % 'uilist' - list of uicontrol lists describing elements properties % { { ui1 }, { ui2 }... }, { 'uiX' } being GUI matlab % uicontrol arguments such as { 'style', 'radiobutton', -% 'String', 'hello' }. See Matlab function uicontrol() for details. +% 'String', 'hello' }. See Matlab function UICONTROL for details. % 'helpcom' - optional help command % 'helpbut' - text for help button % 'title' - optional figure title @@ -49,8 +49,9 @@ % outstruct - returns outputs as a structure (only tagged ui controls % are considered). The field name of the structure is % the tag of the ui and contain the ui value or string. -% instruct - resturn inputs provided in the same format as 'outstruct' +% instruct - returns inputs provided in the same format as 'outstruct' % This allow to compare in/outputs more easy. +% tags - uicontrols by tags % % Note: the function also adds three buttons at the bottom of each % interactive windows: 'CANCEL', 'HELP' (if callback command @@ -67,46 +68,62 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, La Jolla, 1 Feb 2002 % -% See also: supergui(), eeglab() +% See also: SUPERGUI, EEGLAB % Copyright (C) Arnaud Delorme, CNL/Salk Institute, 27 Jan 2002, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [result, userdat, strhalt, resstruct, instruct] = inputgui( varargin); +function [result, userdat, strhalt, resstruct, instruct, alltags] = inputgui( varargin); +result = []; +userdat = []; +strhalt = []; +resstruct = []; if nargin < 2 help inputgui; return; -end; +end % decoding input and backward compatibility % ----------------------------------------- -if isstr(varargin{1}) +if ischar(varargin{1}) options = varargin; else options = { 'geometry' 'uilist' 'helpcom' 'title' 'userdata' 'mode' 'geomvert' }; options = { options{1:length(varargin)}; varargin{:} }; options = options(:)'; -end; +end % checking inputs % --------------- g = finputcheck(options, { 'geom' 'cell' [] {}; ... 'geometry' {'cell','integer'} [] []; ... 'uilist' 'cell' [] {}; ... + 'cancel' 'string' [] 'Cancel'; ... 'helpcom' { 'string','cell' } { [] [] } ''; ... 'title' 'string' [] ''; ... 'eval' 'string' [] ''; ... @@ -120,10 +137,10 @@ 'mode' '' [] 'normal'; ... 'geomvert' 'real' [] [] ... }, 'inputgui'); -if isstr(g), error(g); end; +if ischar(g), error(g); end if isempty(g.getresult) - if isstr(g.mode) + if ischar(g.mode) fig = figure('visible', 'off'); set(fig, 'name', g.title); set(fig, 'userdata', g.userdata); @@ -132,85 +149,85 @@ g.geometry = {}; for row = 1:length(oldgeom) g.geometry = { g.geometry{:} ones(1, oldgeom(row)) }; - end; + end end % skip a line - if strcmpi(g.skipline, 'on'), + if strcmpi(g.skipline, 'on') g.geometry = { g.geometry{:} [1] }; if ~isempty(g.geom) for ind = 1:length(g.geom) g.geom{ind}{2} = g.geom{ind}{2}+1; % add one row - end; + end g.geom = { g.geom{:} {1 g.geom{1}{2} [0 g.geom{1}{2}-2] [1 1] } }; - end; + end g.uilist = { g.uilist{:}, {} }; - end; + end % add buttons - if strcmpi(g.addbuttons, 'on'), + if strcmpi(g.addbuttons, 'on') g.geometry = { g.geometry{:} [1 1 1 1] }; if ~isempty(g.geom) for ind = 1:length(g.geom) g.geom{ind}{2} = g.geom{ind}{2}+1; % add one row - end; + end g.geom = { g.geom{:} ... {4 g.geom{1}{2} [0 g.geom{1}{2}-1] [1 1] }, ... {4 g.geom{1}{2} [1 g.geom{1}{2}-1] [1 1] }, ... {4 g.geom{1}{2} [2 g.geom{1}{2}-1] [1 1] }, ... {4 g.geom{1}{2} [3 g.geom{1}{2}-1] [1 1] } }; - end; + end if ~isempty(g.helpcom) if ~iscell(g.helpcom) g.uilist = { g.uilist{:}, { 'width' 80 'align' 'left' 'Style', 'pushbutton', 'string', g.helpbut, 'tag', 'help', 'callback', g.helpcom } {} }; else g.uilist = { g.uilist{:}, { 'width' 80 'align' 'left' 'Style', 'pushbutton', 'string', 'Help gui', 'callback', g.helpcom{1} } }; g.uilist = { g.uilist{:}, { 'width' 80 'align' 'left' 'Style', 'pushbutton', 'string', 'More help', 'callback', g.helpcom{2} } }; - end; + end else g.uilist = { g.uilist{:}, {} {} }; - end; - g.uilist = { g.uilist{:}, { 'width' 80 'align' 'right' 'Style', 'pushbutton', 'string', 'Cancel', 'tag' 'cancel' 'callback', 'close gcbf' } }; + end + g.uilist = { g.uilist{:}, { 'width' 80 'align' 'right' 'Style', 'pushbutton', 'string', g.cancel, 'tag' 'cancel' 'callback', 'close(gcbf)' } }; g.uilist = { g.uilist{:}, { 'width' 80 'align' 'right' 'stickto' 'on' 'Style', 'pushbutton', 'tag', 'ok', 'string', 'OK', 'callback', 'set(gcbo, ''userdata'', ''retuninginputui'');' } }; - end; + end % add the three buttons (CANCEL HELP OK) at the bottom of the GUI % --------------------------------------------------------------- if ~isempty(g.geom) - [tmp tmp2 allobj] = supergui( 'fig', fig, 'minwidth', g.minwidth, 'geom', g.geom, 'uilist', g.uilist, 'screenpos', g.screenpos ); + [~, ~, allobj, alltags] = supergui( 'fig', fig, 'minwidth', g.minwidth, 'geom', g.geom, 'uilist', g.uilist, 'screenpos', g.screenpos); elseif isempty(g.geomvert) - [tmp tmp2 allobj] = supergui( 'fig', fig, 'minwidth', g.minwidth, 'geomhoriz', g.geometry, 'uilist', g.uilist, 'screenpos', g.screenpos ); + [~, ~, allobj, alltags] = supergui( 'fig', fig, 'minwidth', g.minwidth, 'geomhoriz', g.geometry, 'uilist', g.uilist, 'screenpos', g.screenpos); else - if strcmpi(g.skipline, 'on'), g.geomvert = [g.geomvert(:)' 1]; end; - if strcmpi(g.addbuttons, 'on'),g.geomvert = [g.geomvert(:)' 1]; end; - [tmp tmp2 allobj] = supergui( 'fig', fig, 'minwidth', g.minwidth, 'geomhoriz', g.geometry, 'uilist', g.uilist, 'screenpos', g.screenpos, 'geomvert', g.geomvert(:)' ); - end; + if strcmpi(g.skipline, 'on'), g.geomvert = [g.geomvert(:)' 1]; end + if strcmpi(g.addbuttons, 'on'),g.geomvert = [g.geomvert(:)' 1]; end + [~, ~, allobj, alltags] = supergui( 'fig', fig, 'minwidth', g.minwidth, 'geomhoriz', g.geometry, 'uilist', g.uilist, 'screenpos', g.screenpos, 'geomvert', g.geomvert(:)' ); + end else fig = g.mode; set(findobj('parent', fig, 'tag', 'ok'), 'userdata', []); allobj = findobj('parent',fig); allobj = allobj(end:-1:1); - end; + end % evaluate command before waiting? % -------------------------------- - if ~isempty(g.eval), eval(g.eval); end; + if ~isempty(g.eval), eval(g.eval); end instruct = outstruct(allobj); % Getting default values in the GUI. - + % create figure and wait for return % --------------------------------- - if isstr(g.mode) & (strcmpi(g.mode, 'plot') | strcmpi(g.mode, 'return') ) + if ischar(g.mode) && (strcmpi(g.mode, 'plot') || strcmpi(g.mode, 'return') ) if strcmpi(g.mode, 'plot') return; % only plot and returns - end; + end else waitfor( findobj('parent', fig, 'tag', 'ok'), 'userdata'); - end; + end else fig = g.getresult; allobj = findobj('parent',fig); allobj = allobj(end:-1:1); -end; +end result = {}; userdat = []; @@ -224,13 +241,10 @@ strhalt = get(findobj('parent', fig, 'tag', 'ok'), 'userdata'); [resstruct,result] = outstruct(allobj); % Output parameters userdat = get(fig, 'userdata'); -% if nargout >= 4 -% resstruct = myguihandles(fig, g); -% end; -if isempty(g.getresult) && isstr(g.mode) && ( strcmp(g.mode, 'normal') || strcmp(g.mode, 'return') ) +if isempty(g.getresult) && ischar(g.mode) && ( strcmp(g.mode, 'normal') || strcmp(g.mode, 'return') ) close(fig); -end; +end drawnow; % for windows % function for gui res (deprecated) @@ -243,9 +257,9 @@ % case 'edit', g = setfield(g, get(h(index), 'tag'), get(h(index), 'string')); % case { 'value' 'radio' 'checkbox' 'listbox' 'popupmenu' 'radiobutton' }, ... % g = setfield(g, get(h(index), 'tag'), get(h(index), 'value')); -% end; -% catch, end; -% end; +% end +% catch, end +% end function [resstructout, resultout] = outstruct(allobj) counter = 1; @@ -253,30 +267,42 @@ resstructout = []; for index=1:length(allobj) - if isnumeric(allobj), currentobj = allobj(index); - else currentobj = allobj{index}; - end; - if isnumeric(currentobj) | ~isprop(currentobj,'GetPropertySpecification') % To allow new object handles - try, + if iscell(allobj), currentobj = allobj{index}; + else currentobj = allobj(index); + end + if isnumeric(currentobj) || ~isprop(currentobj,'GetPropertySpecification') % To allow new object handles + try objstyle = get(currentobj, 'style'); switch lower( objstyle ) case { 'listbox', 'checkbox', 'radiobutton' 'popupmenu' 'radio' } resultout{counter} = get( currentobj, 'value'); - if ~isempty(get(currentobj, 'tag')), resstructout = setfield(resstructout, get(currentobj, 'tag'), resultout{counter}); end; + if ~isempty(get(currentobj, 'tag')), + try + resstructout = setfield(resstructout, get(currentobj, 'tag'), resultout{counter}); + catch + fprintf('Warning: tag "%" may not be use as field in output structure', get(currentobj, 'tag')); + end + end counter = counter+1; case 'edit' resultout{counter} = get( currentobj, 'string'); - if ~isempty(get(currentobj, 'tag')), resstructout = setfield(resstructout, get(currentobj, 'tag'), resultout{counter}); end; + if ~isempty(get(currentobj, 'tag')), + try + resstructout = setfield(resstructout, get(currentobj, 'tag'), resultout{counter}); + catch + fprintf('Warning: tag "%" may not be use as field in output structure', get(currentobj, 'tag')); + end + end counter = counter+1; - end; - catch, end; + end + catch, end else ps = currentobj.GetPropertySpecification; resultout{counter} = arg_tovals(ps,false); count = 1; while isfield(resstructout, ['propgrid' int2str(count)]) count = count + 1; - end; + end resstructout = setfield(resstructout, ['propgrid' int2str(count)], arg_tovals(ps,false)); - end; -end; \ No newline at end of file + end +end diff --git a/functions/guifunc/listdlg2.m b/functions/guifunc/listdlg2.m index daa91005c..ed579cf96 100644 --- a/functions/guifunc/listdlg2.m +++ b/functions/guifunc/listdlg2.m @@ -1,81 +1,92 @@ -% listdlg2() - listdlg function clone with coloring and help for -% eeglab(). +% LISTDLG2 - listdlg function clone with coloring and help for +% EEGLAB. % -% Usage: same as listdlg() +% Usage: same as LISTDLG % % Author: Arnaud Delorme, CNL / Salk Institute, La Jolla, 16 August 2002 % -% See also: inputdlg2(), errordlg2(), supergui(), inputgui() +% See also: INPUTDLG2, ERRORDLG2, SUPERGUI, INPUTGUI % Copyright (C) Arnaud Delorme, CNL / Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [vals, okornot, strval] = listdlg2(varargin); if nargin < 2 help listdlg2; return; -end; +end for index = 1:length(varargin) - if iscell(varargin{index}), varargin{index} = { varargin{index} }; end; - if isstr(varargin{index}), varargin{index} = lower(varargin{index}); end; -end; + if iscell(varargin{index}), varargin{index} = { varargin{index} }; end + if ischar(varargin{index}), varargin{index} = lower(varargin{index}); end +end g = struct(varargin{:}); -try, g.promptstring; catch, g.promptstring = ''; end; -try, g.liststring; catch, error('''liststring'' must be defined'); end; -try, g.selectionmode; catch, g.selectionmode = 'multiple'; end; -try, g.listsize; catch, g.listsize = []; end; -try, g.initialvalue; catch, g.initialvalue = []; end; -try, g.name; catch, g.name = ''; end; +try, g.promptstring; catch, g.promptstring = ''; end +try, g.liststring; catch, error('''liststring'' must be defined'); end +try, g.selectionmode; catch, g.selectionmode = 'multiple'; end +try, g.listsize; catch, g.listsize = []; end +try, g.initialvalue; catch, g.initialvalue = []; end +try, g.name; catch, g.name = ''; end fig = figure('visible', 'off'); set(gcf, 'name', g.name); -if isstr(g.liststring) +if ischar(g.liststring) allstr = g.liststring; else allstr = ''; for index = 1:length(g.liststring) allstr = [ allstr '|' g.liststring{index} ]; - end; + end allstr = allstr(2:end); -end; +end geometry = {[1] [1 1]}; geomvert = [min(length(g.liststring), 10) 1]; -if ~strcmpi(g.selectionmode, 'multiple') | ... - (iscell(g.liststring) & length(g.liststring) == 1) | ... - (isstr (g.liststring) & size (g.liststring,1) == 1 & isempty(find(g.liststring == '|'))) - if isempty(g.initialvalue), g.initialvalue = 1; end; +if ~strcmpi(g.selectionmode, 'multiple') || ... + (iscell(g.liststring) && length(g.liststring) == 1) || ... + (isstr (g.liststring) && size (g.liststring,1) == 1 && isempty(find(g.liststring == '|'))) + if isempty(g.initialvalue), g.initialvalue = 1; end minval = 1; maxval = 1; else minval = 0; maxval = 2; -end; +end listui = {{ 'Style', 'listbox', 'tag', 'listboxvals', 'string', allstr, 'max', maxval, 'min', minval } ... { 'Style', 'pushbutton', 'string', 'Cancel', 'callback', ['set(gcbf, ''userdata'', ''cancel'');'] } ... { 'Style', 'pushbutton', 'string', 'Ok' , 'callback', ['set(gcbf, ''userdata'', ''ok'');'] } }; if ~isempty(g.promptstring) geometry = {[1] geometry{:}}; - geomvert = [1 geomvert]; + geomvert = [2 geomvert]; listui = { { 'Style', 'text', 'string', g.promptstring } listui{:}}; -end; -[tmp tmp2 allobj] = supergui( fig, geometry, geomvert, listui{:} ); +end +[tmp, tmp2, allobj] = supergui( fig, geometry, geomvert, listui{:} ); % assign value to listbox % must be done after creating it @@ -86,7 +97,7 @@ if ~isempty(g.listsize) pos = get(gcf, 'position'); set(gcf, 'position', [ pos(1:2) g.listsize]); -end; +end h = findobj( 'parent', fig, 'tag', 'listboxvals'); okornot = 0; @@ -101,18 +112,18 @@ if iscell(g.liststring) for index = vals strval = [ strval ' ' g.liststring{index} ]; - end; + end else for index = vals strval = [ strval ' ' g.liststring(index,:) ]; - end; + end end; strval = strval(2:end); if strcmp(get(fig, 'userdata'), 'cancel') okornot = 0; else okornot = 1; - end; + end close(fig); drawnow; -end; +end diff --git a/functions/guifunc/pophelp.m b/functions/guifunc/pophelp.m index 236a9e91e..0037e24c9 100644 --- a/functions/guifunc/pophelp.m +++ b/functions/guifunc/pophelp.m @@ -1,4 +1,4 @@ -% pophelp() - Same as matlab HTHELP but does not crash under windows. +% POPHELP - Same as matlab HTHELP but does not crash under windows. % % Usage: >> pophelp( function ); % >> pophelp( function, nonmatlab ); @@ -10,42 +10,61 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % -% See also: eeglab() +% See also: EEGLAB % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 pophelp( funct, nonmatlab ); +function pophelp( funct, nonmatlab ) if nargin <1 help pophelp; return; -end; +end if nargin <2 nonmatlab = 0; -end; +end if exist('help2html') if length(funct) > 3 && strcmpi(funct(end-3:end), '.txt') - web(funct); + %web(funct); + fid = fopen(funct, 'r'); + text1 = textscan(fid, '%s', 'delimiter', ''); + fclose(fid); + text1 = cellfun(@(x)[10 x], text1{1}, 'uniformoutput', false); + tmp = char('text://
', text1{:});
+        tmp = tmp';
+        tmp = tmp(:);
+        web( tmp' );
     else
         pathHelpHTML = fileparts(which('help2html'));
-        if ~isempty(findstr('NFT', pathHelpHTML)), rmpath(pathHelpHTML); end;
+        if ~isempty(findstr('NFT', pathHelpHTML)), rmpath(pathHelpHTML); end
         text1 = help2html(funct);
-        if length(funct) > 4 & strcmpi(funct(1:4), 'pop_')
+        if length(funct) > 4 && strcmpi(funct(1:4), 'pop_')
             try,
                 text2 = help2html(funct(5:end));
                 text1 = [text1 '
___________________________________________________________________' 10 ...
@@ -53,18 +72,27 @@
                                ' The ''pop'' function above calls the eponymous Matlab function below' 10 ...
                                ' and could use some of its optional parameters' 10 ...
                                '___________________________________________________________________


' text2 ]; - catch, end; - end; - - web([ 'text://' text1 ]); - end; + catch, end + end + if exist('OCTAVE_VERSION','builtin') == 0 + web([ 'text://' text1 ]); + else + disp(text1); + end + end else - if isempty(funct), return; end; + if exist('OCTAVE_VERSION','builtin') == 0 + doc(funct); + return; + end + + if isempty(funct), return; end doc1 = readfunc(funct, nonmatlab); - if length(funct) > 4 & strcmpi(funct(1:4), 'pop_') + if length(funct) > 4 && strcmpi(funct(1:4), 'pop_') try, doc2 = readfunc(funct(5:end), nonmatlab); - doc1 = { doc1{:} ' _________________________________________________________________ ' ... + doc1 = { doc1{:} ' ' ... + ' _________________________________________________________________ ' ... ' ' ... ' The ''pop'' function above calls the eponymous Matlab function below, ' ... ' which may contain more information for some parameters. '... @@ -72,31 +100,62 @@ ' _________________________________________________________________ ' ... ' ' ... doc2{:} }; - catch, end; - end; + catch, end + end + + if exist('OCTAVE_VERSION','builtin') ~= 0 + for iRow = 1:length(doc1) + disp(doc1{iRow}); + end + return + end + + % write file for help only + icadefs; + if ~isempty(EEGOPTION_PATH) % in icadefs above + homefolder = EEGOPTION_PATH; + elseif ispc + homefolder = getenv('USERPROFILE'); + else homefolder = '~'; + end + + [~,funct] = fileparts(funct); + fileTmp = fullfile(homefolder, [ funct '_doc.m' ]); + fid = fopen(fileTmp, 'w'); + if fid ~= -1 + for iDoc = 1:length(doc1) + fprintf(fid, '%%%s\n', doc1{iDoc}); + end + fclose(fid); + doc(fileTmp); + drawnow; pause(2); + delete(fileTmp); + else + textgui(doc1); + h = findobj('parent', gcf, 'style', 'slider'); + try + icadefs; + catch + GUIBUTTONCOLOR = [0.8 0.8 0.8]; + GUITEXTCOLOR = 'k'; + end + set(h, 'backgroundcolor', GUIBUTTONCOLOR); + h = findobj('parent', gcf, 'style', 'pushbutton'); + set(h, 'backgroundcolor', GUIBUTTONCOLOR); + h = findobj('parent', gca); + set(h, 'color', GUITEXTCOLOR); + set(gcf, 'color', BACKCOLOR); + end - textgui(doc1);1000 - h = findobj('parent', gcf, 'style', 'slider'); - try, icadefs; catch, - GUIBUTTONCOLOR = [0.8 0.8 0.8]; - GUITEXTCOLOR = 'k'; - end; - set(h, 'backgroundcolor', GUIBUTTONCOLOR); - h = findobj('parent', gcf, 'style', 'pushbutton'); - set(h, 'backgroundcolor', GUIBUTTONCOLOR); - h = findobj('parent', gca); - set(h, 'color', GUITEXTCOLOR); - set(gcf, 'color', BACKCOLOR); -end; +end return; function [doc] = readfunc(funct, nonmatlab) doc = {}; if iseeglabdeployed - if isempty(find(funct == '.')), funct = [ funct '.m' ]; end; - funct = fullfile(eeglabexefolder, 'help', funct); -end; + warndlg2([ 'Some help menus not available in compiled version.' 10 'Look up help online.' ] ); +end if nonmatlab fid = fopen( funct, 'r'); else @@ -104,17 +163,17 @@ fid = fopen( funct, 'r'); else fid = fopen( [funct '.m'], 'r'); - end; -end; + end +end if fid == -1 error('File not found'); -end; +end sub = 1; try, - if ~isunix, sub = 0; end; -catch, end; + if ~isunix, sub = 0; end +catch, end if nonmatlab str = fgets( fid ); @@ -122,13 +181,13 @@ str = deblank(str(1:end-sub)); doc = { doc{:} str(1:end) }; str = fgets( fid ); - end; + end else str = fgets( fid ); while (str(1) == '%') str = deblank(str(1:end-sub)); doc = { doc{:} str(2:end) }; str = fgets( fid ); - end; -end; + end +end fclose(fid); diff --git a/functions/guifunc/questdlg2.m b/functions/guifunc/questdlg2.m index f81647bed..ecdb96d0a 100644 --- a/functions/guifunc/questdlg2.m +++ b/functions/guifunc/questdlg2.m @@ -1,46 +1,56 @@ -% questdlg2() - questdlg function clone with coloring and help for -% eeglab(). +% QUESTDLG2 - questdlg function clone with coloring and help for +% EEGLAB. % -% Usage: same as questdlg() +% Usage: same as QUESTDLG % % Warning: % Case of button text and result might be changed by the function % % Author: Arnaud Delorme, CNL / Salk Institute, La Jolla, 11 August 2002 % -% See also: inputdlg2(), errordlg2(), supergui(), inputgui() +% See also: INPUTDLG2, ERRORDLG2, SUPERGUI, INPUTGUI % Copyright (C) Arnaud Delorme, CNL / Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [result] = questdlg2(Prompt,Title,varargin); +function [result] = questdlg2(Prompt,Title,varargin) result = ''; if nargin < 2 help questdlg2; return; -end; +end if isempty(varargin) varargin = { 'Yes' 'No' 'Cancel' 'Yes' }; -end; -result = varargin{end}; -if Prompt(end) == 10, Prompt(end) = []; end; -if Prompt(end) == 10, Prompt(end) = []; end; -if Prompt(end) == 10, Prompt(end) = []; end; -if Prompt(end) == 10, Prompt(end) = []; end; +end +if Prompt(end) == 10, Prompt(end) = []; end +if Prompt(end) == 10, Prompt(end) = []; end +if Prompt(end) == 10, Prompt(end) = []; end +if Prompt(end) == 10, Prompt(end) = []; end fig = figure('visible', 'off'); set(gcf, 'name', Title); @@ -49,43 +59,51 @@ geometry = {}; if ~isempty(find(Prompt == 10)) indlines = find(Prompt == 10); - if indlines(1) ~= 1, indlines = [ 0 indlines ]; end; - if indlines(end) ~= length(Prompt), indlines = [ indlines length(Prompt)+1 ]; end; + if indlines(1) ~= 1, indlines = [ 0 indlines ]; end + if indlines(end) ~= length(Prompt), indlines = [ indlines length(Prompt)+1 ]; end for index = 1:length(indlines)-1 geometry{index} = [1]; listui{index} = { 'Style', 'text', 'string' Prompt(indlines(index)+1:indlines(index+1)-1) }; - end; + end else for index = 1:size(Prompt,1) geometry{index} = [1]; listui{index} = { 'Style', 'text', 'string' Prompt(index,:) }; - end; -end; + end +end listui{end+1} = {}; +width = 80; geometry = { geometry{:} 1 ones(1,length(varargin)-1) }; for index = 1:length(varargin)-1 % ignoring default val - listui = {listui{:} { 'width',80,'align','center','Style', 'pushbutton', 'string', varargin{index}, 'callback', ['set(gcbf, ''userdata'', ''' varargin{index} ''');'] } }; + if index == 1 + if length(varargin{index}) > 15 + width = 160; + elseif length(varargin{index}) > 10 + width = 120; + end + end + listui = {listui{:} { 'width',width,'align','center','Style', 'pushbutton', 'string', varargin{index}, 'callback', ['set(gcbf, ''userdata'', ''' varargin{index} ''');'] } }; if strcmp(varargin{index}, varargin{end}) listui{end}{end+1} = 'fontweight'; listui{end}{end+1} = 'bold'; - end; -end; + end +end %cr = length(find(Prompt == char(10)))+1; %if cr == 1 % cr = size(Prompt,1); -%end; +%end %cr = cr^(7/); -%if cr >= 8, cr = cr-1; end; -%if cr >= 4, cr = cr-1; end; +%if cr >= 8, cr = cr-1; end +%if cr >= 4, cr = cr-1; end %[tmp tmp2 allobj] = supergui( 'fig', fig, 'geomhoriz', geometry, 'geomvert', [cr 1 1], 'uilist', listui, ... [tmp tmp2 allobj] = supergui( 'fig', fig, 'geomhoriz', geometry, 'uilist', listui, ... - 'borders', [0.02 0.015 0.08 0.06], 'spacing', [0 0], 'horizontalalignment', 'left', 'adjustbuttonwidth', 'on' ); + 'borders', [0.05 0.015 0.08 0.06], 'spacing', [0 0], 'horizontalalignment', 'left', 'adjustbuttonwidth', 'off' ); waitfor( fig, 'userdata'); try, result = get(fig, 'userdata'); close(fig); drawnow; -end; +end diff --git a/functions/guifunc/supergui.m b/functions/guifunc/supergui.m index 718ea0111..1971eb251 100644 --- a/functions/guifunc/supergui.m +++ b/functions/guifunc/supergui.m @@ -1,8 +1,8 @@ -% supergui() - a comprehensive gui automatic builder. This function help +% SUPERGUI - a comprehensive gui automatic builder. This function help % to create GUI very fast without bothering about the % positions of the elements. After creating a geometry, % elements just place themselves into the predefined -% locations. It is especially usefull for figure where you +% locations. It is especially useful for figure where you % intend to put text button and descriptions. % % Usage: @@ -34,7 +34,7 @@ % 'uilist' - list of uicontrol lists describing elements properties % { { ui1 }, { ui2 }... }, { 'uiX' } being GUI matlab % uicontrol arguments such as { 'style', 'radiobutton', -% 'String', 'hello' }. See Matlab function uicontrol() for details. +% 'String', 'hello' }. See Matlab function UICONTROL for details. % 'borders' - [left right top bottom] GUI internal borders in normalized % units (0 to 1). Default values are % 'title' - optional figure title @@ -44,7 +44,7 @@ % 'insetv' - vertical space between elements. Default is 2% % of window height. % 'spacing' - [horiz vert] spacing in normalized units. Default -% 'spacingtype' - ['absolute'|'proportional'] abolute means that the +% 'spacingtype' - ['absolute'|'proportional'] absolute means that the % spacing values are fixed. Proportional means that they % depend on the number of element in a line. % 'minwidth' - [integer] minimal width in pixels. Default is none. @@ -60,7 +60,7 @@ % Output: % handles - all the handles of the elements (in the same order as the % uilist input). -% height - adviced height for the figure (so the text look nice). +% height - advised height for the figure (so the text look nice). % allhandles - all the handles in object format % % Example: @@ -71,25 +71,36 @@ % % Author: Arnaud Delorme, CNL / Salk Institute, La Jolla, 2001- % -% See also: eeglab() +% See also: EEGLAB % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [handlers, outheight, allhandlers] = supergui( varargin); +function [handlers, outheight, allhandlers, alltags] = supergui( varargin); % handlers cell format % allhandlers linear format @@ -99,7 +110,7 @@ if nargin < 2 help supergui; return; -end; +end % get version and % set additional parameters @@ -110,13 +121,13 @@ if versnum >= 7.14 addParamFont = { 'fontsize' 12 }; else addParamFont = { }; -end; +end warning off MATLAB:hg:uicontrol:ParameterValuesMustBeValid % decoding input and backward compatibility % ----------------------------------------- -if isstr(varargin{1}) +if ischar(varargin{1}) options = varargin; else options = { 'fig' varargin{1} 'geomhoriz' varargin{2} ... @@ -137,25 +148,25 @@ 'spacing' 'real' [] [0.02 0.01]; 'inseth' 'real' [] 0.02; % x border absolute (5% of width) 'insetv' 'real' [] 0.02 }, 'supergui'); -if isstr(g), error(g); end +if ischar(g), error(g); end if ~isempty(g.geomhoriz) maxcount = sum(cellfun('length', g.geomhoriz)); if maxcount ~= length(g.uilist) warning('Wrong size for ''geomhoriz'' input'); - end; + end if ~isempty(g.geomvert) if length(g.geomvert) ~= length(g.geomhoriz) warning('Wrong size for ''geomvert'' input'); - end; - end; + end + end g.insetv = g.insetv/length(g.geomhoriz); -end; +end if ~isempty(g.geom) if length(g.geom) ~= length(g.uilist) warning('Wrong size for ''geom'' input'); - end; + end maxcount = length(g.geom); -end; +end % create new figure % ----------------- @@ -165,12 +176,12 @@ % converting the geometry formats % ------------------------------- -if ~isempty(g.geomhoriz) & ~iscell( g.geomhoriz ) +if ~isempty(g.geomhoriz) && ~iscell( g.geomhoriz ) oldgeom = g.geomhoriz; g.geomhoriz = {}; for row = 1:length(oldgeom) g.geomhoriz = { g.geomhoriz{:} ones(1, oldgeom(row)) }; - end; + end end if isempty(g.geomvert) g.geomvert = ones(1, length(g.geomhoriz)); @@ -191,14 +202,14 @@ g.geom{count} = { length(g.geomhoriz{row}) sumvert [incx incy] [g.geomhoriz{row}(column)*ratio g.geomvert(row)] }; incx = incx+g.geomhoriz{row}(column)*ratio; count = count+1; - end; + end incy = incy+g.geomvert(row); - end; + end g.borders(1:2) = g.borders(1:2)/maxhoriz*5; g.borders(3:4) = g.borders(3:4)/sumvert*10; g.spacing(1) = g.spacing(1)/maxhoriz*5; g.spacing(2) = g.spacing(2)/sumvert*10; -end; +end % disp new geometry % ----------------- @@ -207,9 +218,9 @@ for index = 1:length(g.geom) fprintf('{ %g %g [%g %g] [%g %g] } ...\n', g.geom{index}{1}, g.geom{index}{2}, ... g.geom{index}{3}(1), g.geom{index}{3}(2), g.geom{index}{4}(1), g.geom{index}{3}(2)); - end; + end fprintf('};\n'); -end; +end % get axis coordinates % -------------------- @@ -229,12 +240,17 @@ column = 1; % count the elements factmultx = 0; factmulty = 0; %zeros(length(g.geomhoriz)); +transformTextUIList = []; +alltags = []; for counter = 1:maxcount % init clear rowhandle; gm = g.geom{counter}; [posx posy width height] = getcoord(gm{1}, gm{2}, gm{3}, gm{4}, g.borders, g.spacing); +% str1 = sprintf('%d, %d, [%1.2f,%1.2f], [%1.2f,%1.2f]', gm{1}, gm{2}, gm{3}(1), gm{3}(2), gm{4}(1), gm{4}(2)); +% str2 = sprintf('%.4f, ', [posx posy width height]); +% fprintf('%s -> %s -> %s\n', str1, str2, g.uilist{ counter }{4}); try currentelem = g.uilist{ counter }; @@ -257,45 +273,63 @@ [posx posy+hf2*height 0.005 (hf1-hf2+0.1)*height].*s+q, 'style', 'pushbutton', 'string', ''); allhandlers{counter} = uicontrol(g.fig, 'unit', 'normalized', 'position', ... [posx posy+(hf1+hf2)/2*height width/2 0.005].*s+q, 'style', 'pushbutton', 'string', ''); - allhandlers{counter} = 0; + allhandlers{counter} = nan; else - if strcmpi(currentelem{1}, 'width'), + + if strcmpi(currentelem{1}, 'width') curwidth = currentelem{2}; currentelem(1:2) = []; else curwidth = 0; - end; - if strcmpi(currentelem{1}, 'align'), + end + if strcmpi(currentelem{1}, 'align') align = currentelem{2}; currentelem(1:2) = []; else align = 'right'; - end; - if strcmpi(currentelem{1}, 'stickto'), + end + transformText = false; + if strcmpi(currentelem{2}, 'text2') + transformTextUIList = [ transformTextUIList counter ]; + currentelem{2} = 'text'; + end + if strcmpi(currentelem{1}, 'stickto') stickto = currentelem{2}; currentelem(1:2) = []; else stickto = 'none'; - end; + end if strcmpi(currentelem{1}, 'vertshift'), currentelem(1) = []; addvert = -height/2; else addvert = 0; - end; + end if strcmpi(currentelem{1}, 'vertexpand'), heightfactor = currentelem{2}; addvert = -(heightfactor-1)*height; currentelem(1:2) = []; else heightfactor = 1; - end; + end % position adjustment depending on GUI type - if isstr(currentelem{2}) && strcmpi(currentelem{2}, 'popupmenu') - posy = posy-height/10; - end; - if isstr(currentelem{2}) && strcmpi(currentelem{2}, 'text') + if ischar(currentelem{2}) && strcmpi(currentelem{2}, 'popupmenu') + %posy = posy-height/5; + end + if ischar(currentelem{2}) && strcmpi(currentelem{2}, 'text') posy = posy+height/5; - end; + end - if strcmpi(currentelem{1}, 'function'), + if strcmpi(currentelem{1}, 'function') % property grid argument panel = uipanel('Title','','FontSize',12,'BackgroundColor','white','Position',[posx posy+addvert width height*heightfactor].*s+q); allhandlers{counter} = arg_guipanel(panel, currentelem{:}); + elseif strcmpi(currentelem{1}, 'panel') + % property grid argument + uipanel(currentelem{2:end},'FontSize',12,'Position',[posx posy+addvert width height*heightfactor].*s+q); + allhandlers{counter} = nan; + elseif strcmpi(currentelem{1}, 'uitable') + uitable(g.fig, currentelem{2:end}, 'unit', 'normalized', 'Position',[posx posy+addvert width height*heightfactor].*s+q); + allhandlers{counter} = nan; else - allhandlers{counter} = uicontrol(g.fig, 'unit', 'normalized', 'position', ... - [posx posy+addvert width height*heightfactor].*s+q, currentelem{:}, addParamFont{:}); + if ~isempty(strmatch('fontsize', currentelem(1:2:end))) + allhandlers{counter} = uicontrol(g.fig, 'unit', 'normalized', 'position', ... + [posx posy+addvert width height*heightfactor].*s+q, currentelem{:}); + else + allhandlers{counter} = uicontrol(g.fig, 'unit', 'normalized', 'position', ... + [posx posy+addvert width height*heightfactor].*s+q, currentelem{:}, addParamFont{:}); + end % this simply compute a factor so that all uicontrol will be visible % ------------------------------------------------------------------ @@ -309,54 +343,76 @@ curpos(1) = curpos(1)+curpos(3)-curwidth; elseif strcmpi(align, 'center') curpos(1) = curpos(1)+curpos(3)/2-curwidth/2; - end; + end set(allhandlers{counter}, 'position', [ curpos(1) curpos(2) curwidth curpos(4) ]); if strcmpi(stickto, 'on') set( allhandlers{counter-1}, 'units', 'pixels'); curpos2 = get(allhandlers{counter-1}, 'position'); set(allhandlers{counter-1}, 'position', [ curpos(1)-curpos2(3)-10 curpos2(2) curpos2(3) curpos2(4) ]); set( allhandlers{counter-1}, 'units', 'normalized'); - end; + end curext(3) = curwidth; - end; + end set( allhandlers{counter}, 'units', 'normalized'); - end; + end if ~strcmp(style, 'edit') && (~strcmp(style, 'pushbutton') || strcmpi(g.adjustbuttonwidth, 'on')) - %tmp = curext(3)/curpos(3); - %if tmp > 3*factmultx && factmultx > 0, adsfasd; end; - factmultx = max(factmultx, curext(3)/curpos(3)); - if strcmp(style, 'pushbutton'), factmultx = factmultx*1.1; end; - end; - if ~strcmp(style, 'listbox') + if strcmpi( currentelem{3}, 'string') && (~iscell(currentelem{4}) || ... + (~isempty(currentelem{4}) && isempty(findstr('html', currentelem{4}{1})))) + %tmp = curext(3)/curpos(3); + %if tmp > 3*factmultx && factmultx > 0, adsfasd; end + if exist('OCTAVE_VERSION','builtin') ~= 0 + curtxt = get(allhandlers{counter}, 'string'); + if ischar(curtxt) + nLines = length(find(curtxt == 10))+1; + curext(3) = curext(3)/nLines; + end + end + + if curext(3)/curpos(3) < 3 + factmultx = max(factmultx, curext(3)/curpos(3)); + end + tmptxt = get(allhandlers{counter}, 'string'); +% % text to get which UI modify horizontal size +% if iscell(tmptxt) fprintf('%s -> %f\n', 'cell', curext(3)/curpos(3)); +% else fprintf('%s -> %f\n', tmptxt, curext(3)/curpos(3)); +% end + if strcmp(style, 'pushbutton'), factmultx = factmultx*1.1; end + end + end + if ~strcmp(style, 'listbox') && ~strcmp(style, 'popupmenu') factmulty = max(factmulty, curext(4)/curpos(4)); - end; - - % Uniformize button text aspect (first letter must be upercase) + end + + % Uniformize button text aspect (first letter must be uppercase) % ----------------------------- - if strcmp(style, 'pushbutton') + if strcmp(style, 'pushbutton') && ishandle(allhandlers{counter}) tmptext = get(allhandlers{counter}, 'string'); if length(tmptext) > 1 if upper(tmptext(1)) ~= tmptext(1) || lower(tmptext(2)) ~= tmptext(2) && ~strcmpi(tmptext, 'STATS') tmptext = lower(tmptext); - try, tmptext(1) = upper(tmptext(1)); catch, end; - end; - end; + try, tmptext(1) = upper(tmptext(1)); catch, end + end + end set(allhandlers{counter}, 'string', tmptext); - end; - end; + end + + try + currentelemstruct = struct(currentelem{:}); + alltags.(currentelemstruct.tag) = allhandlers{counter}; + catch, end + end else - allhandlers{counter} = 0; - end; -end; + allhandlers{counter} = nan; + end +end % adjustments % ----------- -factmultx = factmultx*1.02;% because some text was still hidden -%factmultx = factmultx*1.2; +factmultx = factmultx*1.1;% because some text was still hidden if factmultx < 0.1 factmultx = 0.1; -end; +end % for MAC (magnify figures that have edit fields) % ------- @@ -367,9 +423,13 @@ factmulty = factmulty*1.5; elseif ~isunix % windows factmulty = factmulty*1.08; - end; -catch, end; -factmulty = factmulty*0.9; % global shinking + end +catch, end +if exist('OCTAVE_VERSION', 'builtin') == 0 + factmulty = factmulty*0.9; % global shinking +else + factmulty = factmulty*1.5; +end warning on; % scale and replace the figure in the screen @@ -377,8 +437,8 @@ pos = get(g.fig, 'position'); if factmulty > 1 pos(2) = max(0,pos(2)+pos(4)-pos(4)*factmulty); -end; -pos(1) = pos(1)+pos(3)*(1-factmultx)/2; +end +pos(1) = max(0,pos(1)+pos(3)*(1-factmultx)/2); pos(3) = max(pos(3)*factmultx, g.minwidth); pos(4) = pos(4)*factmulty; set(g.fig, 'position', pos); @@ -386,16 +446,16 @@ % vertical alignment to bottom for text (isnumeric by ishanlde was changed here) % --------------------------------------- for index = 1:length(allhandlers) - if allhandlers{index} ~= 0 && ishandle(allhandlers{index}) + if ishandle(allhandlers{index}) if strcmp(get(allhandlers{index}, 'style'), 'text') set(allhandlers{index}, 'unit', 'pixel'); curpos = get(allhandlers{index}, 'position'); curext = get(allhandlers{index}, 'extent'); set(allhandlers{index}, 'position', [curpos(1) curpos(2)-4 curpos(3) curext(4)]); set(allhandlers{index}, 'unit', 'normalized'); - end; - end; -end; + end + end +end % setting defaults colors %------------------------ @@ -404,11 +464,11 @@ GUIBACKCOLOR = [.8 .8 .8]; GUIPOPBUTTONCOLOR = [.8 .8 .8]; GUITEXTCOLOR = [0 0 0]; -end; +end numobjects = cellfun(@ishandle, allhandlers); % (isnumeric by ishanlde was changed here) allhandlersnum = [ allhandlers{numobjects} ]; -hh = findobj(allhandlersnum, 'parent', g.fig, 'style', 'text'); +hh = findobj(allhandlersnum,'flat', 'parent', g.fig, 'style', 'text'); %set(hh, 'BackgroundColor', get(g.fig, 'color'), 'horizontalalignment', 'left'); set(hh, 'Backgroundcolor', GUIBACKCOLOR); set(hh, 'foregroundcolor', GUITEXTCOLOR); @@ -418,25 +478,25 @@ end set(hh, 'horizontalalignment', g.horizontalalignment); -hh = findobj(allhandlersnum, 'style', 'edit'); +hh = findobj(allhandlersnum,'flat', 'style', 'edit'); set(hh, 'BackgroundColor', [1 1 1]); %, 'horizontalalignment', 'right'); -hh =findobj(allhandlersnum, 'parent', g.fig, 'style', 'pushbutton'); +hh =findobj(allhandlersnum,'flat', 'parent', g.fig, 'style', 'pushbutton'); comp = computer; if length(comp) < 3 || ~strcmpi(comp(1:3), 'MAC') % this puts the wrong background on macs set(hh, 'backgroundcolor', GUIPOPBUTTONCOLOR); set(hh, 'foregroundcolor', GUITEXTCOLOR); -end; -hh =findobj(allhandlersnum, 'parent', g.fig, 'style', 'popupmenu'); +end +hh =findobj(allhandlersnum,'flat', 'parent', g.fig, 'style', 'popupmenu'); set(hh, 'backgroundcolor', GUIPOPBUTTONCOLOR); set(hh, 'foregroundcolor', GUITEXTCOLOR); -hh =findobj(allhandlersnum, 'parent', g.fig, 'style', 'checkbox'); +hh =findobj(allhandlersnum,'flat', 'parent', g.fig, 'style', 'checkbox'); set(hh, 'backgroundcolor', GUIBACKCOLOR); set(hh, 'foregroundcolor', GUITEXTCOLOR); -hh =findobj(allhandlersnum, 'parent', g.fig, 'style', 'listbox'); +hh =findobj(allhandlersnum,'flat', 'parent', g.fig, 'style', 'listbox'); set(hh, 'backgroundcolor', GUIPOPBUTTONCOLOR); set(hh, 'foregroundcolor', GUITEXTCOLOR); -hh =findobj(allhandlersnum, 'parent', g.fig, 'style', 'radio'); +hh =findobj(allhandlersnum,'flat', 'parent', g.fig, 'style', 'radio'); set(hh, 'foregroundcolor', GUITEXTCOLOR); set(hh, 'backgroundcolor', GUIPOPBUTTONCOLOR); set(g.fig, 'visible', 'on'); @@ -452,13 +512,29 @@ pos(1) = (screenSize(3)-pos(3))/2; pos(2) = (screenSize(4)-pos(4))/2+pos(4); set(g.fig, 'position', pos); - end; + end end; % set userdata and title % ---------------------- -if ~isempty(g.userdata), set(g.fig, 'userdata', g.userdata); end; -if ~isempty(g.title ), set(g.fig, 'name', g.title ); end; +if ~isempty(g.userdata), set(g.fig, 'userdata', g.userdata); end +if ~isempty(g.title ), set(g.fig, 'name', g.title ); end + +% transform selected text UI +% -------------------------- +a = axes('position', [0 0 1 1]); +for iList = transformTextUIList + set(allhandlers{iList}, 'unit', 'normalized'); + sTmp = get(allhandlers{iList},'string'); + pTmp = get(allhandlers{iList},'position'); + eTmp = get(allhandlers{iList},'extent'); + tTmp = get(allhandlers{iList},'tag'); + % Remove the UICONTROL + delete(allhandlers{iList}); + % Replace it with a TEXT object + allhandlers{iList} = text(pTmp(1),pTmp(2),sTmp, 'interpreter','latex', 'tag', tTmp); +end +set(a, 'visible', 'off'); return; diff --git a/functions/guifunc/warndlg2.m b/functions/guifunc/warndlg2.m index 70f8f8aba..644f1a496 100644 --- a/functions/guifunc/warndlg2.m +++ b/functions/guifunc/warndlg2.m @@ -1,28 +1,43 @@ -% warndlg2() - same as warndlg for eeglab() +% WARNDLG2 - same as warndlg for EEGLAB % % Author: Arnaud Delorme, CNL / Salk Institute, 12 August 2002 % -% See also: inputdlg2(), questdlg2() +% See also: INPUTDLG2, QUESTDLG2 % Copyright (C) Arnaud Delorme, CNL / Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 warndlg2(Prompt, Title); +function warndlg2(Prompt, Title, modal) if nargin <2 Title = 'Warning'; -end; -questdlg2(Prompt, Title, 'OK', 'OK'); +end +if nargin > 2 && ischar(modal) && strcmpi(modal, 'non-modal') + warndlg(Prompt, Title, 'non-modal') +else + questdlg2(Prompt, Title, 'OK', 'OK'); +end diff --git a/functions/javachatfunc/Chat_with_pane.jar b/functions/javachatfunc/Chat_with_pane.jar deleted file mode 100644 index 423fef359..000000000 Binary files a/functions/javachatfunc/Chat_with_pane.jar and /dev/null differ diff --git a/functions/javachatfunc/startpane.m b/functions/javachatfunc/startpane.m deleted file mode 100644 index 1bf214cd6..000000000 --- a/functions/javachatfunc/startpane.m +++ /dev/null @@ -1,12 +0,0 @@ -import client.EEGLABChat; -import client.VisualToolbar; -import java.awt.*; -import javax.swing.*; - -tb = VisualToolbar(); -F = gcf; -tb.setPreferredSize(Dimension(0, 75)); - -javacomponent(tb,'South',F); - -refresh(F); diff --git a/functions/javachatfunc/update.m b/functions/javachatfunc/update.m deleted file mode 100644 index ee78d1d93..000000000 --- a/functions/javachatfunc/update.m +++ /dev/null @@ -1 +0,0 @@ -tb.RefreshToolbar(); diff --git a/functions/miscfunc/abspeak.m b/functions/miscfunc/abspeak.m index be5ae149d..68b2b258a 100644 --- a/functions/miscfunc/abspeak.m +++ b/functions/miscfunc/abspeak.m @@ -1,4 +1,4 @@ -% abspeak() - find peak amps/latencies in each row of a single-epoch data matrix +% ABSPEAK - find peak amps/latencies in each row of a single-epoch data matrix % % Usage: % >> [amps,frames,signs] = abspeak(data); @@ -17,19 +17,30 @@ % Copyright (C) 1998 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 3-9-98 added frames arg -sm % 01-25-02 reformated help & license -ad diff --git a/functions/miscfunc/arrow.m b/functions/miscfunc/arrow.m index bb16209d1..806a10ba3 100755 --- a/functions/miscfunc/arrow.m +++ b/functions/miscfunc/arrow.m @@ -1,1191 +1,6 @@ +function varargout = arrow( varargin ) -% arrow() - Draw a line with an arrowhead. -% -% Usage: -% >> arrow('Property1',PropVal1,'Property2',PropVal2,...) -% >> arrow(H,'Prop1',PropVal1,...) -% >> arrow(Start,Stop) -% >> arrow(Start,Stop,Length,BaseAngle,TipAngle,Width,Page,CrossDir) -% >> arrow demo %2-D demos of the capabilities of arrow() -% >> arrow demo2 %3-D demos of the capabilities of arrow() -% -% Inputs: -% H - vector of handles to previously created arrows and/or -% line objects, will update the previously-created -% arrows according to the current view and any specified -% properties, and will convert two-point line objects to -% corresponding arrows. Note that arrow(H) will update the -% arrows if the current view has changed. -% Start - vectors of length 2 or 3, or matrices with 2 or 3 columns -% Stop - same as Start -% 'Start' - The starting points. B -% 'Stop' - The end points. /|\ ^ -% 'Length' - Length of the arrowhead in pixels. /|||\ | -% 'BaseAngle' - Base angle in degrees (ADE). //|||\\ L| -% 'TipAngle' - Tip angle in degrees (ABC). ///|||\\\ e| -% 'Width' - Width of the base in pixels. ////|||\\\\ n| -% 'Page' - Use hardcopy proportions. /////|D|\\\\\ g| -% 'CrossDir' - Vector || to arrowhead plane. //// ||| \\\\ t| -% 'NormalDir' - Vector out of arrowhead plane. /// ||| \\\ h| -% 'Ends' - Which end has an arrowhead. //<----->|| \\ | -% 'ObjectHandles' - Vector of handles to update. / base ||| \ V -% 'LineStyle' - The linestyle of the arrow. E angle||<-------->C -% 'LineWidth' - Line thicknesses. |||tipangle -% 'FaceColor' - FaceColor of patch arrows. ||| -% 'EdgeColor' - EdgeColor/Color of patch/line arrows. ||| -% 'Color' - Set FaceColor & EdgeColor properties. -->|A|<-- width -% -% Notes: -% A property list can follow any specified normal argument list, e.g., -% ARROW([1 2 3],[0 0 0],36,'BaseAngle',60) creates an arrow from (1,2,3) to -% the origin, with an arrowhead of length 36 pixels and 60-degree base angle. -% -% The basic arguments or properties can generally be vectorized to create -% multiple arrows with the same call. This is done by passing a property -% with one row per arrow, or, if all arrows are to have the same property -% value, just one row may be specified. -% -% You may want to execute AXIS(AXIS) before calling ARROW so it doesn't change -% the axes on you; ARROW determines the sizes of arrow components BEFORE the -% arrow is plotted, so if ARROW changes axis limits, arrows may be malformed. -% -% ARROW uses features of Matlab 4.2c and later, so earlier versions may be -% incompatible; call ARROW VERSION for more details. -% -% Author: Erik A. Johnson , 1995 - -% Copyright (c)1995, Erik A. Johnson , 10/6/95 - -% Many thanks to Keith Rogers for his many excellent -% suggestions and beta testing. Check out his shareware package MATDRAW. -% He has permission to distribute ARROW with MATDRAW. - - -% $Log: arrow.m,v $ -% Revision 1.5 2009/10/20 22:19:56 dev -% -% added log to file -% - - -function [h,yy,zz] = arrow(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8, ... - arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16, ... - arg17,arg18,arg19,arg20,arg21,arg22,arg23,arg24) - -% Are we doing the demo? -c = sprintf('\n'); -if (nargin==1), - if (ischar(arg1)), - arg1 = lower([arg1 ' ']); - if (strcmp(arg1(1:4),'prop')), - disp([c ... - 'ARROW Properties: Default values are given in [square brackets], and other' c ... - ' acceptable equivalent property names are in (parenthesis).' c c ... - ' Start The starting points. For N arrows, B' c ... - ' this should be a Nx2 or Nx3 matrix. /|\ ^' c ... - ' Stop The end points. For N arrows, this /|||\ |' c ... - ' should be a Nx2 or Nx3 matrix. //|||\\ L|' c ... - ' Length Length of the arrowhead (in pixels on ///|||\\\ e|' c ... - ' screen, points on a page). [16] (Len) ////|||\\\\ n|' c ... - ' BaseAngle Angle (degrees) of the base angle /////|D|\\\\\ g|' c ... - ' ADE. For a simple stick arrow, use //// ||| \\\\ t|' c ... - ' BaseAngle=TipAngle. [90] (Base) /// ||| \\\ h|' c ... - ' TipAngle Angle (degrees) of tip angle ABC. //<----->|| \\ |' c ... - ' [16] (Tip) / base ||| \ V' c ... - ' Width Width of the base in pixels. Not E angle ||<-------->C' c ... - ' the ''LineWidth'' prop. [0] (Wid) |||tipangle' c ... - ' Page If provided, non-empty, and not NaN, |||' c ... - ' this causes ARROW to use hardcopy |||' c ... - ' rather than onscreen proportions. A' c ... - ' This is important if screen aspect --> <-- width' c ... - ' ratio and hardcopy aspect ratio are ----CrossDir---->' c ... - ' vastly different. []' c... - ' CrossDir A vector giving the direction towards which the fletches' c ... - ' on the arrow should go. [computed such that it is perpen-' c ... - ' dicular to both the arrow direction and the view direction' c ... - ' (i.e., as if it was pasted on a normal 2-D graph)] (Note' c ... - ' that CrossDir is a vector; if an axis is plotted on a log' c ... - ' scale, then the corresponding component of CrossDir must' c ... - ' also be set appropriately, i.e., to 1 for no change in' c ... - ' that direction, >1 for a positive change, >0 and <1 for' c ... - ' negative change.)' c ... - ' NormalDir A vector normal to the fletch direction (CrossDir is then' c ... - ' computed by the vector cross product {Line}x{NormalDir}). []' c ... - ' Ends Set which end has an arrowhead. Valid values are ''none'',' c ... - ' ''stop'', ''start'', and ''both''. [''stop''] (End)' c... - ' ObjectHandles Vector of handles to previously-created arrows to be' c ... - ' updated or line objects to be converted to arrows.' c ... - ' [] (Object,Handle)' c ... - ' LineStyle The linestyle of the arrow. If anything other than ''-'',' c ... - ' the arrow will be drawn with a line object, otherwise it' c ... - ' will be drawn with a patch. [''-''] (LineS)' c ... - ' LineWidth Same as used in SET commands, but may be passed a vector' c ... - ' for multiple arrows. [default of the line or patch]' c ... - ' FaceColor Set the FaceColor of patch arrows. May be one of' c ... - ' ''ymcrgbwkfn'' (f=flat,n=none) or a column-vector colorspec' c ... - ' (or Nx3 matrix for N arrows). [1 1 1] (FaceC)' c ... - ' EdgeColor Set the EdgeColor of patch arrows and Color of line' c ... - ' arrows. [1 1 1] (EdgeC)' c ... - ' Color Sets both FaceColor and EdgeColor properties.' c ... - ' Included for compatibility with line objects.' c c ... - ' ARROW(''Start'',P,''Stop'',[]) or ARROW(''Start'',[],''Stop'',P), with size(P)=[N 3]' c ... - ' will create N-1 arrows, just like ARROW(''Start'',P1,''Stop'',P2), where' c c ... - ' / x1 y1 z1 \ / x1 y1 z1 \ / x2 y2 z2 \' c ... - ' | . . . | | . . . | | . . . |' c ... - ' P = | . . . | P1 = | . . . | P2 = | . . . |' c ... - ' | . . . | | . . . | | . . . |' c ... - ' \ xN yN zN / \ xN-1 yN-1 zN-1 / \ xN yN zN /' c]); - elseif (strcmp(arg1(1:4),'vers')), - disp([c ... - 'ARROW Version: There are two compatibility problems for ARROW in Matlab' c ... - ' versions earlier than 4.2c:' c c c ... - ' 1) In Matlab <4.2, the ''Tag'' property does not exist. ARROW uses this' c ... - ' ''Tag'' to identify arrow objects for subsequent calls to ARROW.' c c ... - ' Solution: (a) delete all instances of the string' c c ... - ' ,''Tag'',ArrowTag' c c ... - ' (b) and replace all instances of the string' c c ... - ' strcmp(get(oh,''Tag''),ArrowTag)' c c ... - ' with the string' c c ... - ' all(size(ud)==[1 15])' c c c ... - ' 2) In Matlab <4.2c, FINDOBJ is buggy (it can cause Matlab to crash if' c ... - ' more than 100 objects are returned). ARROW uses FINDOBJ to make sure' c ... - ' that any handles it receives are truly handles to existing objects.' c c ... - ' Solution: replace the line' c c ... - ' objs = findobj;' c c ... - ' with the lines' c c ... - ' objs=0; k=1;' c ... - ' while (k<=length(objs)),' c ... - ' objs = [objs; get(objs(k),''Children'')];' c ... - ' if (strcmp(get(objs(k),''Type''),''axes'')),' c ... - ' objs=[objs;get(objs(k),''XLabel''); ...' c ... - ' get(objs(k),''YLabel''); ...' c ... - ' get(objs(k),''ZLabel''); ...' c ... - ' get(objs(k),''Title'')];' c ... - ' end;' c ... - ' k=k+1;' c ... - ' end;' c c]); - elseif (strcmp(arg1(1:4),'demo')), - % demo - % create the data - [x,y,z] = peaks; - [ddd,iii]=max(z(:)); - axlim = [min(x(:)) max(x(:)) min(y(:)) max(y(:)) min(z(:)) max(z(:))]; - - % modify it by inserting some NaN's - [m,n] = size(z); - m = floor(m/2); - n = floor(n/2); - z(1:m,1:n) = NaN*ones(m,n); - - % graph it - clf('reset'); - hs=surf(x,y,z); - xlabel('x'); ylabel('y'); - - if (~strcmp(arg1(1:5),'demo2')), - % set the view - axis(axlim); - zlabel('z'); - %shading('interp'); set(hs,'EdgeColor','k'); - view(viewmtx(-37.5,30,20)); - title('Demo of the capabilities of the ARROW function in 3-D'); - - % Normal yellow arrow - h1 = arrow([axlim(1) axlim(4) 4],[-.8 1.2 4], ... - 'EdgeColor','y','FaceColor','y'); - - % Normal white arrow, clipped by the surface - h2 = arrow(axlim([1 4 6]),[0 2 4]); - t=text(-2.4,2.7,7.7,'arrow clipped by surf'); - - % Baseangle<90 - h3 = arrow([3 .125 3.5],[1.375 0.125 3.5],30,50); - t2=text(3.1,.125,3.5,'local maximum'); - - % Baseangle<90, fill and edge colors different - h4 = arrow(axlim(1:2:5)*.5,[0 0 0],36,60,25, ... - 'EdgeColor','b','FaceColor','c'); - t3=text(axlim(1)*.5,axlim(3)*.5,axlim(5)*.5-.75,'origin'); - set(t3,'HorizontalAlignment','center'); - - % Baseangle>90, black fill - h5 = arrow([-2.9 2.9 3],[-1.3 .4 3.2],30,120,[],6, ... - 'EdgeColor','r','FaceColor','k','LineWidth',2); - - % Baseangle>90, no fill - h6 = arrow([-2.9 2.9 1.3],[-1.3 .4 1.5],30,120,[],6, ... - 'EdgeColor','r','FaceColor','none','LineWidth',2); - - % Stick arrow - h7 = arrow([-1.6 -1.65 -6.5],[0 -1.65 -6.5],[],16,16); - t4=text(-1.5,-1.65,-7.25,'global mininum'); - set(t4,'HorizontalAlignment','center'); - - % Normal, black fill - h8 = arrow([-1.4 0 -7.2],[-1.4 0 -3],'FaceColor','k'); - t5=text(-1.5,0,-7.75,'local minimum'); - set(t5,'HorizontalAlignment','center'); - - % Gray fill, crossdir specified - h9 = arrow([-3 2.2 -6],[-3 2.2 -.05],36,[],27,6,[],[0 -1 0], ... - 'EdgeColor','w','FaceColor',.2*[1 1 1]); - - % a series of normal arrows, linearly spaced, crossdir specified - h10y=(0:4)'/3; - h10 = arrow([-3*ones(size(h10y)) h10y -6.5*ones(size(h10y))], ... - [-3*ones(size(h10y)) h10y -.05*ones(size(h10y))], ... - 12,[],[],[],[],[0 -1 0]); - - % a series of normal arrows, linearly spaced - h11x=(1:.33:2.8)'; - h11 = arrow([h11x -3*ones(size(h11x)) 6.5*ones(size(h11x))], ... - [h11x -3*ones(size(h11x)) -.05*ones(size(h11x))]); - - % series of black-filled arrows, radially oriented, crossdir specified - h12x=2; h12y=-3; h12z=axlim(5)/2; h12xr=1; h12zr=h12z; ir=.15;or=.81; - h12t=(0:11)'/6*pi; - h12 = arrow([h12x+h12xr*cos(h12t)*ir h12y*ones(size(h12t)) ... - h12z+h12zr*sin(h12t)*ir],[h12x+h12xr*cos(h12t)*or ... - h12y*ones(size(h12t)) h12z+h12zr*sin(h12t)*or], ... - 10,[],[],[],[], ... - [-h12xr*sin(h12t) zeros(size(h12t)) h12zr*cos(h12t)],... - 'FaceColor','none','EdgeColor','m'); - - % series of normal arrows, tangentially oriented, crossdir specified - or13=.91; h13t=(0:.5:12)'/6*pi; - h13 = arrow([h12x+h12xr*cos(h13t)*or13 ... - h12y*ones(size(h13t)) ... - h12z+h12zr*sin(h13t)*or13],[],6); - - % arrow with no line ==> oriented upwards - h14 = arrow([3 3 3],[3 3 3],30); - t6=text(3,3,3.6,'no line'); set(t6,'HorizontalAlignment','center'); - - % arrow with -- linestyle - h15 = arrow([-.5 -3 -3],[1 -3 -3],'LineStyle','--','EdgeColor','g'); - - if (nargout>=1), h=[h1;h2;h3;h4;h5;h6;h7;h8;h9;h10;h11;h12;h13;h14;h15]; end; - else, - set(hs,'YData',10.^get(hs,'YData')); - shading('interp'); - view(2); - title('Demo of the capabilities of the ARROW function in 2-D'); - hold on; [C,H]=contour(x,y,z,20); hold off; - for k=H', set(k,'ZData',(axlim(6)+1)*ones(size(get(k,'XData'))),... - 'YData',10.^get(k,'YData'),'Color','k'); end; - set(gca,'YScale','log'); - axis([axlim(1:2) 10.^axlim(3:4)]); - - % Normal yellow arrow - h1 = arrow([axlim(1) 10^axlim(4) axlim(6)+2],[x(iii) 10^y(iii) axlim(6)+2], ... - 'EdgeColor','y','FaceColor','y'); - - % three arrows with varying fill, width, and baseangle - h2 = arrow([-3 10^(-3) 10; -3 10^(-1.5) 10; -1.5 10^(-3) 10], ... - [-.03 10^(-.03) 10; -.03 10^(-1.5) 10; -1.5 10^(-.03) 10], ... - 24,[90;60;120],[],[0;0;4]); - set(h2(2),'EdgeColor','g','FaceColor','c'); - set(h2(3),'EdgeColor','m','FaceColor','r'); - if (nargout>=1), h=[h1;h2]; end; - end; - else, - error(['ARROW got an unknown single-argument string ''' deblank(arg1) '''.']); - end; - return; - end; -end; - -% Check # of arguments -if (nargin==0), help arrow ; return; -elseif (nargout>3), error('ARROW produces at most 3 output arguments.'); -end; - -% find first property number -firstprop = nargin+1; -if (nargin<=3), % to speed things up a bit - if (nargin==1), - elseif (ischar(arg1)), firstprop=1; - elseif (ischar(arg2)), firstprop=2; - elseif (nargin==3), - if (ischar(arg3)), firstprop=3; end; - end; -else, - for k=1:nargin, - curarg = eval(['arg' num2str(k)]); - if (ischar(curarg)), - firstprop = k; - break; - end; - end; -end; - -% check property list -if (firstprop<=nargin), - for k=firstprop:2:nargin, - curarg = eval(['arg' num2str(k)]); - if ((~ischar(curarg))|(min(size(curarg))~=1)), - error('ARROW requires that a property name be a single string.'); - end; - end; - if (rem(nargin-firstprop,2)~=1), - error(['ARROW requires that the property ''' eval(['arg' num2str(nargin)]) ... - ''' be paired with a property value.']); - end; -end; - -% default output -if (nargout>0), h=[]; end; -if (nargout>1), yy=[]; end; -if (nargout>2), zz=[]; end; - -% set values to empty matrices -start = []; -stop = []; -len = []; -baseangle = []; -tipangle = []; -wid = []; -page = []; -crossdir = []; -ends = []; -linewidth = []; -linestyle = []; -edgecolor = []; -facecolor = []; -ax = []; -oldh = []; -defstart = [NaN NaN NaN]; -defstop = [NaN NaN NaN]; -deflen = 16; -defbaseangle = 90; -deftipangle = 16; -defwid = 0; -defpage = 0; -defcrossdir = [NaN NaN NaN]; -defends = 1; -deflinewidth = NaN; -deflinestyle = '- '; -defedgecolor = [1 1 1]; -deffacecolor = [1 1 1]; -defoldh = []; - -% The 'Tag' we'll put on our arrows -ArrowTag = 'Arrow'; - -% check for oldstyle arguments -if (firstprop>2), - % if old style arguments, get them - if (firstprop==3), start=arg1; stop=arg2; - elseif (firstprop==4), start=arg1; stop=arg2; len=arg3(:); - elseif (firstprop==5), start=arg1; stop=arg2; len=arg3(:); baseangle=arg4(:); - elseif (firstprop==6), start=arg1; stop=arg2; len=arg3(:); baseangle=arg4(:); tipangle=arg5(:); - elseif (firstprop==7), start=arg1; stop=arg2; len=arg3(:); baseangle=arg4(:); tipangle=arg5(:); wid=arg6(:); - elseif (firstprop==8), start=arg1; stop=arg2; len=arg3(:); baseangle=arg4(:); tipangle=arg5(:); wid=arg6(:); page=arg7(:); - elseif (firstprop==9), start=arg1; stop=arg2; len=arg3(:); baseangle=arg4(:); tipangle=arg5(:); wid=arg6(:); page=arg7(:); crossdir=arg8; - else, error('ARROW takes at most 8 non-property arguments.'); - end; -elseif (firstprop==2), - % assume arg1 is a set of handles - oldh = arg1(:); -end; - -% parse property pairs -extraprops=char([]); -for k=firstprop:2:nargin, - prop = eval(['arg' num2str(k)]); - val = eval(['arg' num2str(k+1)]); - prop = [lower(prop(:)') ' ']; - if (all(prop(1:5)=='start')), start = val; - elseif (all(prop(1:4)=='stop')), stop = val; - elseif (all(prop(1:3)=='len')), len = val(:); - elseif (all(prop(1:4)=='base')), baseangle = val(:); - elseif (all(prop(1:3)=='tip')), tipangle = val(:); - elseif (all(prop(1:3)=='wid')), wid = val(:); - elseif (all(prop(1:4)=='page')), page = val; - elseif (all(prop(1:5)=='cross')), crossdir = val; - elseif (all(prop(1:4)=='norm')), if (ischar(val)), crossdir=val; else, crossdir=val*sqrt(-1); end; - elseif (all(prop(1:3)=='end')), ends = val; - elseif (all(prop(1:5)=='linew')), linewidth = val(:); - elseif (all(prop(1:5)=='lines')), linestyle = val; - elseif (all(prop(1:5)=='color')), edgecolor = val; facecolor=val; - elseif (all(prop(1:5)=='edgec')), edgecolor = val; - elseif (all(prop(1:5)=='facec')), facecolor = val; - elseif (all(prop(1:6)=='object')), oldh = val(:); - elseif (all(prop(1:6)=='handle')), oldh = val(:); - elseif (all(prop(1:5)=='userd')), %ignore it - else, extraprops=[extraprops ',arg' num2str(k) ',arg' num2str(k+1)]; - end; -end; - -% Check if we got 'default' values -if (ischar(start )), s=lower([start(:)' ' ']); if (all(s(1:3)=='def')), start = defstart; else, error(['ARROW does not recognize ''' start(:)' ''' as a valid ''Start'' string.']); end; end; -if (ischar(stop )), s=lower([stop(:)' ' ']); if (all(s(1:3)=='def')), stop = defstop; else, error(['ARROW does not recognize ''' stop(:)' ''' as a valid ''Stop'' string.']); end; end; -if (ischar(len )), s=lower([len(:)' ' ']); if (all(s(1:3)=='def')), len = deflen; else, error(['ARROW does not recognize ''' len(:)' ''' as a valid ''Length'' string.']); end; end; -if (ischar(baseangle )), s=lower([baseangle(:)' ' ']); if (all(s(1:3)=='def')), baseangle = defbaseangle; else, error(['ARROW does not recognize ''' baseangle(:)' ''' as a valid ''BaseAngle'' string.']); end; end; -if (ischar(tipangle )), s=lower([tipangle(:)' ' ']); if (all(s(1:3)=='def')), tipangle = deftipangle; else, error(['ARROW does not recognize ''' tipangle(:)' ''' as a valid ''TipAngle'' string.']); end; end; -if (ischar(wid )), s=lower([wid(:)' ' ']); if (all(s(1:3)=='def')), wid = defwid; else, error(['ARROW does not recognize ''' wid(:)' ''' as a valid ''Width'' string.']); end; end; -if (ischar(crossdir )), s=lower([crossdir(:)' ' ']); if (all(s(1:3)=='def')), crossdir = defcrossdir; else, error(['ARROW does not recognize ''' crossdir(:)' ''' as a valid ''CrossDir'' or ''NormalDir'' string.']); end; end; -if (ischar(page )), s=lower([page(:)' ' ']); if (all(s(1:3)=='def')), page = defpage; else, error(['ARROW does not recognize ''' page(:)' ''' as a valid ''Page'' string.']); end; end; -if (ischar(ends )), s=lower([ends(:)' ' ']); if (all(s(1:3)=='def')), ends = defends; end; end; -if (ischar(linewidth )), s=lower([linewidth(:)' ' ']); if (all(s(1:3)=='def')), linewidth = deflinewidth; else, error(['ARROW does not recognize ''' linewidth(:)' ''' as a valid ''LineWidth'' string.']); end; end; -if (ischar(linestyle )), s=lower([linestyle(:)' ' ']); if (all(s(1:3)=='def')), linestyle = deflinestyle; end; end; -if (ischar(edgecolor )), s=lower([edgecolor(:)' ' ']); if (all(s(1:3)=='def')), edgecolor = defedgecolor; end; end; -if (ischar(facecolor )), s=lower([facecolor(:)' ' ']); if (all(s(1:3)=='def')), facecolor = deffacecolor; end; end; -if (ischar(oldh )), s=lower([oldh(:)' ' ']); if (all(s(1:3)=='def')), oldh = []; else, error(['ARROW does not recognize ''' oldh(:)' ''' as a valid ''ObjectHandles'' string.']); end; end; - -% check transpose on arguments; convert strings to numbers -if (((size(start ,1)==2)|(size(start ,1)==3))&((size(start ,2)==1)|(size(start ,2)>3))), start = start'; end; -if (((size(stop ,1)==2)|(size(stop ,1)==3))&((size(stop ,2)==1)|(size(stop ,2)>3))), stop = stop'; end; -if (((size(crossdir,1)==2)|(size(crossdir,1)==3))&((size(crossdir,2)==1)|(size(crossdir,2)>3))), crossdir = crossdir'; end; -if ((size(linestyle,2)>2)&(size(linestyle,1)<=2)), linestyle=linestyle'; end; -if (all(size(edgecolor))), - if (ischar(edgecolor)), - col = lower(edgecolor(:,1)); - edgecolor = zeros(length(col),3); - ii=find(col=='y'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[1 1 0]; end; - ii=find(col=='m'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[1 0 1]; end; - ii=find(col=='c'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[0 1 1]; end; - ii=find(col=='r'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[1 0 0]; end; - ii=find(col=='g'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[0 1 0]; end; - ii=find(col=='b'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[0 0 1]; end; - ii=find(col=='w'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[1 1 1]; end; - ii=find(col=='k'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[0 0 0]; end; - ii=find(col=='f'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[1 1 1]*inf; end; - ii=find(col=='n'); if (all(size(ii))), edgecolor(ii,:)=ones(length(ii),1)*[1 1 1]*(-inf); end; - elseif ((size(edgecolor,2)~=3)&(size(edgecolor,1)==3)), - edgecolor=edgecolor'; - elseif (size(edgecolor,2)~=3), - error('ARROW requires that color specifications must be a ?x3 RGB matrix.'); - end; -end; -if (all(size(facecolor))), - if (ischar(facecolor)), - col = lower(facecolor(:,1)); - facecolor = zeros(length(col),3); - ii=find(col=='y'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[1 1 0]; end; - ii=find(col=='m'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[1 0 1]; end; - ii=find(col=='c'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[0 1 1]; end; - ii=find(col=='r'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[1 0 0]; end; - ii=find(col=='g'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[0 1 0]; end; - ii=find(col=='b'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[0 0 1]; end; - ii=find(col=='w'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[1 1 1]; end; - ii=find(col=='k'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[0 0 0]; end; - ii=find(col=='f'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[1 1 1]*inf; end; - ii=find(col=='n'); if (all(size(ii))), facecolor(ii,:)=ones(length(ii),1)*[1 1 1]*(-inf); end; - elseif ((size(facecolor,2)~=3)&(size(facecolor,1)==3)), - facecolor=facecolor'; - elseif (size(facecolor,2)~=3), - error('ARROW requires that color specifications must be a ?x3 RGB matrix.'); - end; -end; -if (all(size(ends))), - if (ischar(ends)), - endsorig = ends; - col = lower([ends(:,1:min(3,size(ends,2))) ones(size(ends,1),max(0,3-size(ends,2)))*' ']); - ends = NaN*ones(size(ends,1),1); - oo = ones(1,size(ends,1)); - ii=find(all(col'==['non']'*oo)'); if (all(size(ii))), ends(ii)=ones(length(ii),1)*0; end; - ii=find(all(col'==['sto']'*oo)'); if (all(size(ii))), ends(ii)=ones(length(ii),1)*1; end; - ii=find(all(col'==['sta']'*oo)'); if (all(size(ii))), ends(ii)=ones(length(ii),1)*2; end; - ii=find(all(col'==['bot']'*oo)'); if (all(size(ii))), ends(ii)=ones(length(ii),1)*3; end; - if (any(isnan(ends))), - ii = min(find(isnan(ends))); - error(['ARROW does not recognize ''' deblank(endsorig(ii,:)) ''' as a valid ''Ends'' value.']); - end; - else, - ends = ends(:); - end; -end; -oldh = oldh(:); - -% check object handles -if (all(size(oldh))), - oldh = oldh.'; - objs = findobj; - if (length(objs)==0), error('ARROW found no graphics handles.'); - elseif (length(objs)==1), objs=[objs;objs]; end; - if (~all(any(objs(:,ones(1,length(oldh)))==oldh(ones(length(objs),1),:)))), - error('ARROW got invalid object handles.'); - end; - oldh = oldh.'; -end; - -% Check for an empty Start or Stop (but not both) with no object handles -if ((~all(size(oldh)))&(all(size(start))~=all(size(stop)))), - if (~all(size(start))), start=stop; end; - ii = find(all(diff(start)'==0)'); - if (size(start,1)==1), - stop = start; - elseif (length(ii)==size(start,1)-1) - stop = start(1,:); - start = stop; - else, - if (all(size(ii))), - jj = (1:size(start,1))'; - jj(ii) = zeros(length(ii),1); - jj = jj(find(jj>0)); - start = start(jj,:); - end; - stop = start(2:size(start,1),:); - start = start(1:size(start,1)-1,:); - end; -end; - -% largest argument length -argsizes = [length(oldh) size(start,1) size(stop,1) ... - length(len) length(baseangle) length(tipangle) ... - length(wid) length(page) size(crossdir,1) length(ends) ... - length(linewidth) size(edgecolor,1) size(facecolor,1)]; -args=['length(ObjectHandle) '; ... - '#rows(Start) '; ... - '#rows(Stop) '; ... - 'length(Length) '; ... - 'length(BaseAngle) '; ... - 'length(TipAngle) '; ... - 'length(Width) '; ... - 'length(Page) '; ... - '#rows(CrossDir) '; ... - '#rows(Ends) '; ... - 'length(LineWidth) '; ... - '#colors in EdgeColor '; ... - '#colors in FaceColor ']; -if (any(imag(crossdir(:))~=0)), - args(9,:) = '#rows(NormalDir) '; -end; -if (~all(size(oldh))), - narrows = max(argsizes); -else, - narrows = length(oldh); -end; - -% Check size of arguments -ii = find((argsizes~=0)&(argsizes~=1)&(argsizes~=narrows)); -if (all(size(ii))), - s = args(ii',:); - while ((size(s,2)>1)&((abs(s(:,size(s,2)))==0)|(abs(s(:,size(s,2)))==abs(' ')))), - s = s(:,1:size(s,2)-1); - end; - s = [ones(length(ii),1)*'ARROW requires that ' s ... - ones(length(ii),1)*[' equal the # of arrows (' num2str(narrows) ').' c]]; - s = s'; - s = s(:)'; - s = s(1:length(s)-1); - error(char(s)); -end; - -% check element length in Start, Stop, and CrossDir -if (all(size(start))), - if (size(start,2)==2), - start = [start NaN*ones(size(start,1),1)]; - elseif (size(start,2)~=3), - error('ARROW requires 2- or 3-element Start points.'); - end; -end; -if (all(size(stop))), - if (size(stop,2)==2), - stop = [stop NaN*ones(size(stop,1),1)]; - elseif (size(stop,2)~=3), - error('ARROW requires 2- or 3-element Stop points.'); - end; -end; -if (all(size(crossdir))), - if (size(crossdir,2)<3), - crossdir = [crossdir NaN*ones(size(crossdir,1),3-size(crossdir,2))]; - elseif (size(crossdir,2)~=3), - if (all(imag(crossdir(:))==0)), - error('ARROW requires 2- or 3-element CrossDir vectors.'); - else, - error('ARROW requires 2- or 3-element NormalDir vectors.'); - end; - end; -end; - -% fill empty arguments -if (~all(size(start ))), start = [NaN NaN NaN]; end; -if (~all(size(stop ))), stop = [NaN NaN NaN]; end; -if (~all(size(len ))), len = NaN; end; -if (~all(size(baseangle ))), baseangle = NaN; end; -if (~all(size(tipangle ))), tipangle = NaN; end; -if (~all(size(wid ))), wid = NaN; end; -if (~all(size(page ))), page = NaN; end; -if (~all(size(crossdir ))), crossdir = [NaN NaN NaN]; end; -if (~all(size(ends ))), ends = NaN; end; -if (~all(size(linewidth ))), linewidth = NaN; end; -if (~all(size(linestyle ))), linestyle = char(['-']); end; % was NaN -if (~all(size(edgecolor ))), edgecolor = [NaN NaN NaN]; end; -if (~all(size(facecolor ))), facecolor = [NaN NaN NaN]; end; - -% expand single-column arguments -o = ones(narrows,1); -if (size(start ,1)==1), start = o * start ; end; -if (size(stop ,1)==1), stop = o * stop ; end; -if (length(len )==1), len = o * len ; end; -if (length(baseangle )==1), baseangle = o * baseangle ; end; -if (length(tipangle )==1), tipangle = o * tipangle ; end; -if (length(wid )==1), wid = o * wid ; end; -if (length(page )==1), page = o * page ; end; -if (size(crossdir ,1)==1), crossdir = o * crossdir ; end; -if (length(ends )==1), ends = o * ends ; end; -if (length(linewidth )==1), linewidth = o * linewidth ; end; -if (size(linestyle ,1)==1), linestyle = o * linestyle ; end; -if (size(edgecolor ,1)==1), edgecolor = o * edgecolor ; end; -if (size(facecolor ,1)==1), facecolor = o * facecolor ; end; -ax = o * gca; -if (size(linestyle ,2)==1), linestyle = char([linestyle o*' ']); end; -linestyle = char(linestyle); - -% if we've got handles, get the defaults from the handles -oldlinewidth = NaN*ones(narrows,1); -oldlinestyle = char(zeros(narrows,2)); -oldedgecolor = NaN*ones(narrows,3); -oldfacecolor = NaN*ones(narrows,3); -if (all(size(oldh))), - fromline = zeros(narrows,1); - for k=1:narrows, - oh = oldh(k); - ud = get(oh,'UserData'); - isarrow = strcmp(get(oh,'Tag'),ArrowTag); - ohtype = get(oh,'Type'); - ispatch = strcmp(ohtype,'patch'); - isline = strcmp(ohtype,'line'); - if (isarrow|isline), - % arrow UserData format: [start' stop' len base tip wid page crossdir' ends] - if (isarrow), - start0 = ud(1:3); - stop0 = ud(4:6); - if (isnan(len(k))), len(k) = ud( 7); end; - if (isnan(baseangle(k))), baseangle(k) = ud( 8); end; - if (isnan(tipangle(k))), tipangle(k) = ud( 9); end; - if (isnan(wid(k))), wid(k) = ud(10); end; - if (isnan(page(k))), page(k) = ud(11); end; - if (isnan(crossdir(k,1))), crossdir(k,1) = ud(12); end; - if (isnan(crossdir(k,2))), crossdir(k,2) = ud(13); end; - if (isnan(crossdir(k,3))), crossdir(k,3) = ud(14); end; - if (isnan(ends(k))), ends(k) = ud(15); end; - end; - if (isline), - fromline(k) = 1; - if (isarrow), - fc = -inf*[1 1 1]; - else, - fc = get(oh,'Color'); - x = get(oh,'XData'); - y = get(oh,'YData'); - z = get(oh,'ZData'); - if (any(size(x)~=[1 2])|any(size(y)~=[1 2])), - error('ARROW only converts two-point lines.'); - end; - if (~all(size(z))), z=NaN*ones(size(x)); end; - start0 = [x(1) y(1) z(1)]; - stop0 = [x(2) y(2) z(2)]; - end; - ec = get(oh,'Color'); - ls = [get(oh,'LineStyle') ' ']; ls=char(ls(1:2)); - lw = get(oh,'LineWidth'); - else, % an arrow patch - fc = get(oh,'FaceColor');if (ischar(fc)), - if (strcmp(fc,'none')), fc=-inf*[1 1 1]; - elseif (strcmp(fc,'flat')), fc=inf*[1 1 1]; - else, fc=[1 1 1]; end; - end; - ec = get(oh,'EdgeColor');if (ischar(ec)), - if (strcmp(ec,'none')), ec=-inf*[1 1 1]; - elseif (strcmp(ec,'flat')), ec=inf*[1 1 1]; - else, ec=[1 1 1]; end; - end; - ls = char('- '); - lw = get(oh,'LineWidth'); - end; - ax(k) = get(oh,'Parent'); - else, - error(['ARROW cannot convert ' ohtype ' objects.']); - end; - oldlinewidth(k) = lw; - oldlinestyle(k,:) = ls; - oldedgecolor(k,:) = ec; - oldfacecolor(k,:) = fc; - ii=find(isnan(start(k,:))); if (all(size(ii))), start(k,ii)=start0(ii); end; - ii=find(isnan(stop( k,:))); if (all(size(ii))), stop( k,ii)=stop0( ii); end; - if (isnan(linewidth(k))), linewidth(k) = lw; end; - if (isnan(linestyle(k,1))), linestyle(k,1:2) = ls; end; - if (any(isnan(facecolor(k,:)))), facecolor(k,:) = fc; end; - if (any(isnan(edgecolor(k,:)))), edgecolor(k,:) = ec; end; - end; -else - fromline = []; -end; - -% set up the UserData data -% (do it here so it is not corrupted by log10's and such) -ud = [start stop len baseangle tipangle wid page crossdir ends]; - -% Set Page defaults -if isnan(page) - page = ~isnan(page); -end; - -% Get axes limits, range, min; correct for aspect ratio and log scale -axm = zeros(3,narrows); -axr = zeros(3,narrows); -ap = zeros(2,narrows); -xyzlog = zeros(3,narrows); -limmin = zeros(2,narrows); -limrange = zeros(2,narrows); -oneax = all(ax==ax(1)); -if (oneax), - T = zeros(4,4); - invT = zeros(4,4); -else, - T = zeros(16,narrows); - invT = zeros(16,narrows); -end; -axnotdone = ones(size(ax)); -while (any(axnotdone)), - ii = min(find(axnotdone)); - curax = ax(ii); - curpage = page(ii); - % get axes limits and aspect ratio - axl = [get(curax,'XLim'); get(curax,'YLim'); get(curax,'ZLim')]; - ar = get(curax,'DataAspectRatio'); - % get axes size in pixels (points) - u = get(curax,'Units'); - axposoldunits = get(curax,'Position'); - if (curpage), - curfig = get(curax,'Parent'); - pu = get(curfig,'PaperUnits'); - set(curfig,'PaperUnits','points'); - pp = get(curfig,'PaperPosition'); - set(curfig,'PaperUnits',pu); - set(curax,'Units','normalized'); - curap = get(curax,'Position'); - curap = pp.*curap; - else, - set(curax,'Units','pixels'); - curap = get(curax,'Position'); - end; - set(curax,'Units',u); - set(curax,'Position',axposoldunits); - % adjust limits for log scale on axes - curxyzlog = [strcmp(get(curax,'XScale'),'log'); ... - strcmp(get(curax,'YScale'),'log'); ... - strcmp(get(curax,'ZScale'),'log')]; - if (any(curxyzlog)), - ii = find([curxyzlog;curxyzlog]); - if (any(axl(ii)<=0)), - error('ARROW does not support non-positive limits on log-scaled axes.'); - else, - axl(ii) = log10(axl(ii)); - end; - end; - % correct for aspect ratio - if (~isnan(ar(1))), - if (curap(3) < ar(1)*curap(4)), - curap(2) = curap(2) + (curap(4)-curap(3)/ar(1))/2; - curap(4) = curap(3)/ar(1); - else, - curap(1) = curap(1) + (curap(3)-curap(4)*ar(1))/2; - curap(3) = curap(4)*ar(1); - end; - end; - % correct for 'equal' - % may only want to do this for 2-D views, but seems right for 3-D also - if (~isnan(ar(2))), - if ((curap(3)/(axl(1,2)-axl(1,1)))/(curap(4)/(axl(2,2)-axl(2,1)))>ar(2)), - incr = curap(3)*(axl(2,2)-axl(2,1))/(curap(4)*ar(2)) - (axl(1,2)-axl(1,1)); - axl(1,:) = axl(1,:) + incr/2*[-1 1]; - else, - incr = ar(2)*(axl(1,2)-axl(1,1))*curap(4)/curap(3) - (axl(2,2)-axl(2,1)); - axl(2,:) = axl(2,:) + incr/2*[-1 1]; - end; - end; - % compute the range of 2-D values - curT = get(curax,'Xform'); - lim = curT*[0 1 0 1 0 1 0 1;0 0 1 1 0 0 1 1;0 0 0 0 1 1 1 1;1 1 1 1 1 1 1 1]; - lim = lim(1:2,:)./([1;1]*lim(4,:)); - curlimmin = min(lim')'; - curlimrange = max(lim')' - curlimmin; - curinvT = inv(curT); - if (~oneax), - curT = curT.'; - curinvT = curinvT.'; - curT = curT(:); - curinvT = curinvT(:); - end; - % check which arrows to which cur corresponds - ii = find((ax==curax)&(page==curpage)); - oo = ones(1,length(ii)); - axr(:,ii) = diff(axl')' * oo; - axm(:,ii) = axl(:,1) * oo; - ap(:,ii) = curap(3:4)' * oo; - xyzlog(:,ii) = curxyzlog * oo; - limmin(:,ii) = curlimmin * oo; - limrange(:,ii) = curlimrange * oo; - if (oneax), - T = curT; - invT = curinvT; - else, - T(:,ii) = curT * oo; - invT(:,ii) = curinvT * oo; - end; - axnotdone(ii) = zeros(1,length(ii)); -end; - -% correct for log scales -curxyzlog = xyzlog.'; -ii = find(curxyzlog(:)); -if (all(size(ii))), - start( ii) = real(log10(start( ii))); - stop( ii) = real(log10(stop( ii))); - if (all(imag(crossdir(ii))==0)), - crossdir(ii) = real(log10(crossdir(ii))); - else, - jj = find(imag(crossdir(ii))==0); - if (all(size(jj))), crossdir(jj) = real(log10(crossdir(jj))); end; - jj = find(imag(crossdir(ii))~=0); - if (all(size(jj))), crossdir(jj) = real(log10(imag(crossdir(jj))))*sqrt(-1); end; - end; -end; - -% take care of defaults, page was done above -ii=find(isnan(start(:) )); if (all(size(ii))), start(ii) = axm(ii)+axr(ii)/2; end; -ii=find(isnan(stop(:) )); if (all(size(ii))), stop(ii) = axm(ii)+axr(ii)/2; end; -ii=find(isnan(crossdir(:) )); if (all(size(ii))), crossdir(ii) = zeros(length(ii),1); end; -ii=find(isnan(len )); if (all(size(ii))), len(ii) = ones(length(ii),1)*deflen; end; -ii=find(isnan(baseangle )); if (all(size(ii))), baseangle(ii) = ones(length(ii),1)*defbaseangle; end; -ii=find(isnan(tipangle )); if (all(size(ii))), tipangle(ii) = ones(length(ii),1)*deftipangle; end; -ii=find(isnan(wid )); if (all(size(ii))), wid(ii) = ones(length(ii),1)*defwid; end; -ii=find(isnan(ends )); if (all(size(ii))), ends(ii) = ones(length(ii),1)*defends; end; -ii=find(isnan(linewidth )); if (all(size(ii))), linewidth(ii) = ones(length(ii),1)*deflinewidth; end; -ii=find(any(isnan(edgecolor'))); if (all(size(ii))), edgecolor(ii,:) = ones(length(ii),1)*defedgecolor; end; -ii=find(any(isnan(facecolor'))); if (all(size(ii))), facecolor(ii,:) = ones(length(ii),1)*deffacecolor; end; -ii=find(isnan(linestyle(:,1) )); if (all(size(ii))), linestyle(ii,:) = ones(length(ii),1)*deflinestyle; end; -ii=find(isnan(linestyle(:,2) )); if (all(size(ii))), linestyle(ii,2) = ones(length(ii),1)*' '; end; %just in case - -% transpose all values -start = start.'; -stop = stop.'; -len = len.'; -baseangle = baseangle.'; -tipangle = tipangle.'; -wid = wid.'; -page = page.'; -crossdir = crossdir.'; -ends = ends.'; -linewidth = linewidth.'; -linestyle = linestyle.'; -facecolor = facecolor.'; -edgecolor = edgecolor.'; -fromline = fromline.'; -ax = ax.'; -oldlinewidth = oldlinewidth.'; -oldlinestyle = oldlinestyle.'; -oldedgecolor = oldedgecolor.'; -oldfacecolor = oldfacecolor.'; - -% given x, a 3xN matrix of points in 3-space; -% want to convert to X, the corresponding 4xN 2-space matrix -% -% tmp1=[(x-axm)./axr; ones(1,size(x,1))]; -% if (oneax), X=T*tmp1; -% else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1; -% tmp2=zeros(4,4*N); tmp2(:)=tmp1(:); -% X=zeros(4,N); X(:)=sum(tmp2)'; end; -% X = X ./ (X(:,4)*ones(1,4)); - -% for all points with start==stop, start=stop-(verysmallvalue)*(up-direction); -ii = find(all(start==stop)); -if (all(size(ii))), - % find an arrowdir vertical on screen and perpendicular to viewer - % transform to 2-D - tmp1 = [(stop(:,ii)-axm(:,ii))./axr(:,ii);ones(1,length(ii))]; - if (oneax), twoD=T*tmp1; - else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,ii).*tmp1; - tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:); - twoD=zeros(4,length(ii)); twoD(:)=sum(tmp2)'; end; - twoD=twoD./(ones(4,1)*twoD(4,:)); - % move the start point down just slightly - tmp1 = twoD + [0;-1/1000;0;0]*(limrange(2,ii)./ap(2,ii)); - % transform back to 3-D - if (oneax), threeD=invT*tmp1; - else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT(:,ii).*tmp1; - tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:); - threeD=zeros(4,length(ii)); threeD(:)=sum(tmp2)'; end; - start(:,ii) = (threeD(1:3,:)./(ones(3,1)*threeD(4,:))).*axr(:,ii)+axm(:,ii); -end; - -% compute along-arrow points -% transform Start points - tmp1=[(start-axm)./axr;ones(1,narrows)]; - if (oneax), X0=T*tmp1; - else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1; - tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:); - X0=zeros(4,narrows); X0(:)=sum(tmp2)'; end; - X0=X0./(ones(4,1)*X0(4,:)); -% transform Stop points - tmp1=[(stop-axm)./axr;ones(1,narrows)]; - if (oneax), Xf=T*tmp1; - else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1; - tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:); - Xf=zeros(4,narrows); Xf(:)=sum(tmp2)'; end; - Xf=Xf./(ones(4,1)*Xf(4,:)); -% compute pixel distance between points - D = sqrt(sum(((Xf(1:2,:)-X0(1:2,:)).*(ap./limrange)).^2)); -% compute and modify along-arrow distances - len1 = len; - len2 = len - (len.*tan(tipangle/180*pi)-wid/2).*tan((90-baseangle)/180*pi); - slen0 = zeros(1,narrows); - slen1 = len1 .* ((ends==2)|(ends==3)); - slen2 = len2 .* ((ends==2)|(ends==3)); - len0 = zeros(1,narrows); - len1 = len1 .* ((ends==1)|(ends==3)); - len2 = len2 .* ((ends==1)|(ends==3)); - % for no start arrowhead - ii=find((ends==1)&(D0), h=H; end; -else, - % don't create the patch, just return the data - h=x; - yy=y; - zz=z; -end; +disp('The arrow function was removed from EEGLAB') +disp('because of lack of compatibility with Matlab 2019') +disp('An updated version of the function is available at') +disp('https://www.mathworks.com/matlabcentral/fileexchange/278-arrow') diff --git a/functions/miscfunc/averef.m b/functions/miscfunc/averef.m index f6d6cbfec..b68d0881c 100644 --- a/functions/miscfunc/averef.m +++ b/functions/miscfunc/averef.m @@ -1,6 +1,6 @@ -% averef() - convert common-reference EEG data to average reference +% AVEREF - convert common-reference EEG data to average reference % Note that this old function is not being used in EEGLAB. The -% function used by EEGLAB is reref(). +% function used by EEGLAB is REREF. % % Usage: % >> data = averef(data); @@ -13,7 +13,7 @@ % Outputs: % data_out - Input data converted to average reference. % W_out - ICA weight matrix converted to average reference -% S_out - ICA sphere matrix converted to eye() +% S_out - ICA sphere matrix converted to EYE % meandata - (1,dataframes) mean removed from each data frame (point) % % Note: If 2 args, also converts the weight matrix W to average reference: @@ -24,23 +24,34 @@ % % Authors: Scott Makeig and Arnaud Delorme, SCCN/INC/UCSD, La Jolla, 1999 % -% See also: reref() +% See also: REREF % Copyright (C) 1999 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 12/16/99 Corrected denomiator on the suggestion of Ian Nimmo-Smith, Cambridge UK % 01-25-02 reformated help & license -ad @@ -70,11 +81,11 @@ size1 = size(winv,1); avematrix = eye(size1)-ones(size1)*1/size1; W = pinv(avematrix*winv); -end; +end if nargin >= 3 winv = pinv(W*S); size1 = size(winv,1); avematrix = eye(size1)-ones(size1)*1/size1; W = pinv(avematrix*winv); S = eye(chans); -end; +end diff --git a/functions/miscfunc/brainstorm2eeglab.m b/functions/miscfunc/brainstorm2eeglab.m new file mode 100644 index 000000000..45cc0619b --- /dev/null +++ b/functions/miscfunc/brainstorm2eeglab.m @@ -0,0 +1,139 @@ +% brainstorm2eeglab - convert Brainstorm structures to EEGLAB dataset +% +% EEG = brainstorm2eeglab(bst, epochType); +% +% Inputs: +% bst - Brainstorm string for a folder containing data epoch files or Brainstorm +% data epoch structure +% epochType - [string] epoch type. Only import these epochs which +% Comment field contains this string +% +% Limitations: +% - Only import data epochs +% - Cannot import linked file +% +% Output: +% EEG - EEGLAB structure +% +% Author: Arnaud Delorme, UCSD + +% Copyright (C) Arnaud Delorme, UCSD 2022 +% +% 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 = brainstorm2eeglab(bst, epochType) + +if nargin < 1 + help brainstorm2eeglab; + return; +end +if nargin < 2 + epochType = ''; +end + +if ischar(bst) + oriBst = bst; + bst = dir(fullfile(bst, '*.mat')); + if isempty(bst) + error('Files not found') + end +else + oriBst = ''; + % Need brainstrorm + try + prot = bst_get('ProtocolInfo'); + catch + brainstorm nogui + try + prot = bst_get('ProtocolInfo'); + catch + error('Brainstorm not found. Brainstorm must be installed and running.') + end + end + brainstorm_path = bst_get('BrainstormDbDir'); + protocol = prot.Comment; + + for iEpoch = 1:length(bst) + bst(iEpoch).name = bst(iEpoch).FileName; + bst(iEpoch).folder = fullfile(brainstorm_path, protocol, 'data'); + end +end + +disp('Reading data epochs...'); +allEpochs = {}; +for iEpoch = 1:length(bst) + if ~isequal(bst(iEpoch).name, 'brainstormstudy.mat') + epochStruct = load('-mat', fullfile(bst(iEpoch).folder, bst(iEpoch).name)); + % epochStruct.Comment(1) contain the type of event + % events not imported (in epochStruct.event) + if ~isempty(epochType) + if contains(epochStruct.Comment, epochType) + allEpochs{end+1} = epochStruct.F; + end + else + allEpochs{end+1} = epochStruct.F; + end + end +end +data = reshape([allEpochs{:}], size(allEpochs{1},1), size(allEpochs{1},2), length(allEpochs)); + +% create EEG structure +EEG = eeg_emptyset; +EEG.srate = mean(1./diff(epochStruct.Time)); +EEG.data = data; % microvolts +EEG.xmin = epochStruct.Time(1); + +% channel locations +if isempty(oriBst) + chanFile = fullfile(bst(1).folder, bst(1).ChannelFile); +else + chanFile = fullfile(oriBst, '..', '@default_study', 'channel.mat'); +end +if exist(chanFile, 'file') + chans = load('-mat', chanFile); + for iChan = 1:length(chans.Channel) + EEG.chanlocs(iChan).labels = chans.Channel(iChan).Name; + if ~isempty(chans.Channel(iChan).Loc) + EEG.chanlocs(iChan).X = chans.Channel(iChan).Loc(1); + EEG.chanlocs(iChan).Y = chans.Channel(iChan).Loc(2); + EEG.chanlocs(iChan).Z = chans.Channel(iChan).Loc(3); + end + EEG.chanlocs(iChan).type = chans.Channel(iChan).Type; + end + EEG.chanlocs = convertlocs(EEG.chanlocs, 'cart2all'); +end +EEG = eeg_checkset(EEG); + +% rescale data to microvolts +if ~isempty(EEG.chanlocs) + chanTypes = strmatch('EEG', { EEG.chanlocs.type }); + if ~isempty(chanTypes) + EEG.data(chanTypes,:,:) = EEG.data(chanTypes,:,:)*1e6; % assumes volt (this code should not be reached as channel types should always be defined) + end +else + EEG.data = EEG.data*1e6; % assumes volt (this code should not be reached as channel types should always be defined) +end + diff --git a/functions/miscfunc/caliper.m b/functions/miscfunc/caliper.m index 8087c9dc5..727b51213 100644 --- a/functions/miscfunc/caliper.m +++ b/functions/miscfunc/caliper.m @@ -1,4 +1,4 @@ -% caliper() - Measure a set of spatial components of a given data epoch relative to +% CALIPER - Measure a set of spatial components of a given data epoch relative to % a reference epoch and decomposition. % Usage: % >> [amp,window]=caliper(newepoch,refepoch,weights,compnums,filtnums,times,'noplot'); @@ -17,7 +17,7 @@ % windows = (length(compnums)),length(times)) matrix of tapering windows used % % Notes: -% Function caliper() works as follows: First the reference epoch is decomposed using +% Function CALIPER works as follows: First the reference epoch is decomposed using % the given weight matrix (may be ICA, PCA, or etc). Next, the time course of the % main lobe of the activation in the reference epoch (from max to 1st min, forward % and backward in time from abs max, optionally after bandpass filtering) is used @@ -33,23 +33,34 @@ % Copyright (C) 11/2000 Scott Makeig & Marissa Westerfield,, SCCN/INC/UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % Edit History: % 12/05/00 -- added fig showing data, ref activation, and window vector -mw -% 12/19/00 -- adjusted new icaproj() args -sm +% 12/19/00 -- adjusted new ICAPROJ args -sm % 01-25-02 reformated help & license -ad function [amps,windows] = caliper(newepoch,refepoch,weights,compnums,filtnums,times,noplot) @@ -66,11 +77,11 @@ nchans = size(newepoch,1); ntimes = size(newepoch,2); -if compnums(1) == 0 | isempty(compnums(1)) +if compnums(1) == 0 || isempty(compnums(1)) compnums = 1:nchans; end -if min(compnums) < 1 | max(compnums) > size(weights,2) +if min(compnums) < 1 || max(compnums) > size(weights,2) help caliper return end @@ -80,7 +91,7 @@ else if isempty(filtnums) filtnums = []; - elseif length(filtnums)==1 & filtnums(1)==0 + elseif length(filtnums)==1 && filtnums(1)==0 filtnums = []; elseif length(filtnums) ~= 3 fprintf('\ncaliper(): filter parameters (filtnums) must have length 3.\n') @@ -88,7 +99,7 @@ end end -if nargin< 6 | isempty(times) | (length(times)==1 & times(1)==0) +if nargin< 6 || isempty(times) || (length(times)==1 && times(1)==0) times = 0:ntimes-1; else if length(times) ~= ntimes @@ -171,7 +182,7 @@ amps = [amps winvrms(c)*sum(refact(n,:).*newact(n,:))]; end n = n+1; - if ~noplot & n <= 4 %%% only plot out at most the first 3 components + if ~noplot && n <= 4 %%% only plot out at most the first 3 components refproj = icaproj(refepoch,weights,c); refproj = env(refproj); windproj = winv(:,c)*(refact(n-1,:)*refnorm); diff --git a/functions/miscfunc/chanproj.m b/functions/miscfunc/chanproj.m index 5b31811ea..2d797c069 100644 --- a/functions/miscfunc/chanproj.m +++ b/functions/miscfunc/chanproj.m @@ -1,11 +1,11 @@ -% chanproj() - make a detailed plot of data returned from plotproj() +% CHANPROJ - make a detailed plot of data returned from PLOTPROJ % for given channel. Returns the data plotted. % Usage: % >> [chandata] = chanproj(projdata,chan); % >> [chandata] = chanproj(projdata,chan,ncomps,framelist,limits,title,colors); % % Inputs: -% projdata = data returned from plotproj() +% projdata = data returned from PLOTPROJ % chan = single channel to plot % ncomps = number of component projections in projdata % @@ -21,26 +21,37 @@ % Copyright (C) 1996 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 11-30-96 Scott Makeig CNL / Salk Institute, La Jolla as plotprojchan.m -% 03-19-97 changed var() to diag(cov()) -sm +% 03-19-97 changed VAR to diag(COV) -sm % 03-26-97 fix (== -> =) -sm % 04-03-97 allow framelist to be a col vector, allow 32 traces, fix pvaf, made % ncomps mandatory -sm -% 04-04-97 shortened name to chanproj() -sm +% 04-04-97 shortened name to CHANPROJ -sm % 05-20-97 added read of icadefs.m -sm % 11-05-97 disallowed white traces unless default axis color is white -sm & ch % 11-13-97 rm'ed errcode variable -sm @@ -73,12 +84,12 @@ [chans,framestot] = size(projdata); frames = fix(framestot/(ncomps+1)); -if ncomps < 1 | frames*(ncomps+1) ~= framestot, +if ncomps < 1 || frames*(ncomps+1) ~= framestot, fprintf(... 'chanproj(): data length (%d) not a multiple of ncomps (%d).\n',... framestot,ncomps); return -end; +end if chan> chans, fprintf(... @@ -88,7 +99,7 @@ else chandata = projdata(chan,:); epochs = fix(length(chandata)/frames); -end; +end if epochs > MAXPLOTDATACHANS fprintf(... 'chanproj(): maximum number of traces to plot is %d\n',... @@ -110,23 +121,23 @@ fprintf( ... 'chanproj():^G limits should be 0 or an array [xmin xmax ymin ymax].\n'); return - end; + end xmin = limits(1); xmax = limits(2); ymin = limits(3); ymax = limits(4); -end; +end -if xmin == 0 & xmax == 0, +if xmin == 0 && xmax == 0, x = [0:frames-1]; xmin = 0; xmax = frames-1; else dx = (xmax-xmin)/(frames-1); x=xmin*ones(1,frames)+dx*(0:frames-1); % construct x-values -end; +end -if ymax == 0 & ymin == 0, +if ymax == 0 && ymin == 0, ymax=max(max(projdata(chan,:))); ymin=min(min(projdata(chan,:))); end @@ -149,7 +160,7 @@ end end -if framelist(1)<1 | framelist(length(framelist))>frames, +if framelist(1)<1 || framelist(length(framelist))>frames, fprintf('chanproj(): framelist values must be between 1-%d.\n',frames); return else @@ -167,7 +178,7 @@ if cid <3, fprintf('chanproj(): cannot open file %s.\n',colorfile); return - end; + end colors = fscanf(cid,'%s',[3 MAXPLOTDATACHANS]); colors = colors'; [r c] = size(colors); @@ -175,12 +186,12 @@ for j=1:c if colors(i,j)=='.', colors(i,j)=' '; - end; - end; - end; + end + end + end else % default color order - no yellow colors =['w ';'r ';'b ';'g ';'c ';'m ';'r ';'b ';'g ';'c ';'m ';'r ';'b ';'g ';'c ';'m ';'r ';'b ';'g ';'c ';'m ';'r ';'b ';'g ';'c ';'m ';'r ';'b ';'g ';'c ';'m ';'r ']; -end; +end % % Make vector of x-values % @@ -215,7 +226,7 @@ plot(x,chandata(e,:),colors(e),'LineWidth',1); % plot it! end hold on; -end; +end fprintf('\n'); % %%%%%%%%%%%%%%%%%%%% Fix axis limits %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/functions/miscfunc/cleanvarname.m b/functions/miscfunc/cleanvarname.m new file mode 100644 index 000000000..993325d14 --- /dev/null +++ b/functions/miscfunc/cleanvarname.m @@ -0,0 +1,62 @@ +function nameout = cleanvarname(namein) + +% Routine to remove unallowed characters from strings +% nameout can be use as a variable or field in a structure +% Cyril Pernet & Arnaud Delorme + +% custom change +if strcmp(namein,'#') + namein = 'nb'; +end + +% 1st change space to underscore (keeps readability) +for l=1:length(namein) + if isspace(namein(l)) + namein(l) = '_'; + end +end + +% keep letters, numbers and underscore +keep = isstrprop(namein, 'alpha') + isstrprop(namein, 'digit'); +underscores = zeros(1,size(namein,2)); +underscores(strfind(namein,'_')) = 1; +keep = keep + underscores; +nameout = namein(logical(keep)); + +% remove usual suspects JIC isstrprop did not work +stringcheck = [strfind(nameout,'('), ... + strfind(nameout,')') ... + strfind(nameout,'[') ... + strfind(nameout,']') ... + strfind(nameout,'{') ... + strfind(nameout,'}') ... + strfind(nameout,'-') ... + strfind(nameout,'+') ... + strfind(nameout,'*') ... + strfind(nameout,'/') ... + strfind(nameout,'#') ... + strfind(nameout,'%') ... + strfind(nameout,'&') ... + strfind(nameout,'@') ... + ]; + +if ~isempty(stringcheck) + nameout(stringcheck) = []; +end + +% No number in position 1 +nb_check = 1; +while nb_check + if isletter(nameout(1)) + nb_check = 0; + elseif strcmp(nameout(1),'_') + nameout(1) = []; + elseif isnumeric(eval(nameout(1))) + nameout(1) = []; + end +end + +% last check +if ~isvarname(nameout) + error('the variable name to use is still invalid, check chars to remove') +end diff --git a/functions/miscfunc/compareeeglabdistrib.m b/functions/miscfunc/compareeeglabdistrib.m new file mode 100644 index 000000000..62fa5f440 --- /dev/null +++ b/functions/miscfunc/compareeeglabdistrib.m @@ -0,0 +1,67 @@ +% compare EEGLAB distributions + +% Copyright (C) 2006 Arnaud Delorme +% +% 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 compareeeglabdistrib(folder1, folder2) + +fileList1 = getmfilelist(folder1); +fileList2 = getmfilelist(folder2); + +% strip list from folders +for iFile = 1:length(fileList1), fileList1{iFile} = fileList1{iFile}(length(folder1)+1:end); end +for iFile = 1:length(fileList2), fileList2{iFile} = fileList2{iFile}(length(folder2)+1:end); end + +for iFile1 = 1:length(fileList1) + iFile2 = strmatch(fileList1{iFile1}, fileList2, 'exact'); + if isempty(iFile2) + fprintf('Missing file %s in folder %s\n', fileList1{iFile1}, folder2); + else + dir1 = dir(fullfile(folder1, fileList1{iFile1})); + dir2 = dir(fullfile(folder2, fileList2{iFile2})); + if length(dir1) ~= 1 || length(dir2) ~= 1 + error('Size error'); + end + if dir1.bytes ~= dir2.bytes + fprintf('Files %s differ\n', fileList2{iFile2}); + %fprintf('---------------------\n'); + %system([ '/usr/bin/diff ' fullfile(folder1, fileList1{iFile1}) ' ' fullfile(folder2, fileList2{iFile2}) ]); + end + fileList2(iFile2) = []; + end +end + +for iFile2 = 1:length(fileList2) + fprintf('Missing file %s in folder %s\n', fileList2{iFile2}, folder1); +end + + + + + + + diff --git a/functions/miscfunc/compdsp.m b/functions/miscfunc/compdsp.m index a2863844d..accc2c9a7 100644 --- a/functions/miscfunc/compdsp.m +++ b/functions/miscfunc/compdsp.m @@ -1,4 +1,4 @@ -% compdsp() - Display standard info figures for a data decomposition +% COMPDSP - Display standard info figures for a data decomposition % Creates four figure windows showing: Component amplitudes, % scalp maps, activations and activation spectra. % Usage: @@ -6,7 +6,7 @@ % % Inputs: % data = data matrix used to train the decomposition -% weights = the unmixing matrix (e.g., weights*sphere from runica()) +% weights = the unmixing matrix (e.g., weights*sphere from RUNICA) % % Optional: % locfile = 2-d electrode locations file (as in >> topoplot example) @@ -16,30 +16,41 @@ % {default|'': none} % compnums = optional vector of component numbers to display % {default|[] -> all} -% amps = all component amplitudes (from runica()) +% amps = all component amplitudes (from RUNICA) % {default|[]->recompute} -% act = activations matrix (from runica()) +% act = activations matrix (from RUNICA) % {default|[]->recompute} % % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 2000 % Copyright (C) 12/16/00 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. -% 02-01-01 replaced std() with rms() -sm +% 02-01-01 replaced STD with RMS -sm % 02-10-01 made srate optional -sm % 01-25-02 reformated help & license -ad @@ -88,7 +99,7 @@ function compdsp(data,unmix,locfile,srate,titl,compnums,amps,act) if nargin<4 srate = 0; % from icadefs end -if isempty(srate) | srate==0 +if isempty(srate) || srate==0 srate = DEFAULT_SRATE; % from icadefs end if nargin<5 @@ -109,7 +120,7 @@ function compdsp(data,unmix,locfile,srate,titl,compnums,amps,act) if isempty(amps) amps = NaN; end -if ~isnan(amps) & length(amps) ~= ncomps +if ~isnan(amps) && length(amps) ~= ncomps error('Supplied amps does not match the number of unmixed components'); end @@ -145,7 +156,7 @@ function compdsp(data,unmix,locfile,srate,titl,compnums,amps,act) fprintf('\n'); elseif size(act,2) ~= frames error('Supplied activations do not match data length'); -elseif size(act,1) ~= ncomps & size(act,1) ~= length(compnums) +elseif size(act,1) ~= ncomps && size(act,1) ~= length(compnums) error('Number of supplied activations matrix does not match data or weights'); elseif size(act,1) == ncomps act = act(compnums,:); % cut down matrix to desired components @@ -185,7 +196,7 @@ function compdsp(data,unmix,locfile,srate,titl,compnums,amps,act) fprintf('\n'); % -%%%%%%%%%%%%%%%%%%%%%% III. eegplot() activations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%% III. EEGPLOT activations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if frames/srate < 10 dispsecs = ceil(frames/srate); @@ -214,7 +225,7 @@ function compdsp(data,unmix,locfile,srate,titl,compnums,amps,act) end % -%%%%%%%%%%%%%%%%%%%%%%% IV. plotdata() spectra %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%% IV. PLOTDATA spectra %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % pos = [620,40,550,400]; figure('Position',pos); diff --git a/functions/miscfunc/compheads.m b/functions/miscfunc/compheads.m index 899e91b13..ee1a5f09d 100644 --- a/functions/miscfunc/compheads.m +++ b/functions/miscfunc/compheads.m @@ -1,4 +1,4 @@ -% compheads() - plot multiple topoplot() maps of ICA component topographies +% COMPHEADS - plot multiple TOPOPLOT maps of ICA component topographies % % Usage: % >> compheads(winv,'spline_file',compnos,'title',rowscols,labels,view) @@ -9,7 +9,7 @@ % defined in the eloc_file. Normally, winv = inv(weights*sphere). % spline_file - Name of the eloctrode position file in BESA spherical coords. % compnos - Vector telling which (order of) component maps to show -% Indices <0 tell compheads() to invert a map; = 0 leave blank subplot +% Indices <0 tell COMPHEADS to invert a map; = 0 leave blank subplot % Example [1 0 -2 3 0 -6] {default|0 -> 1:columns_in_winv} % 'title' - Title string for each page {default|0 -> 'ICA Component Maps'} % rowscols - Vector of the form [m,n] where m is total vertical tiles and n @@ -17,30 +17,41 @@ % multiple figures will be produced {def|0 -> one near-square page}. % labels - Vector of numbers or a matrix of strings to use as labels for % each map {default|0 -> 1:ncolumns_in_winv} -% view - topoplot() view, either [az el] or keyword ('top',...) -% See >> help topoplot() for options. +% view - TOPOPLOT view, either [az el] or keyword ('top',...) +% See >> help TOPOPLOT for options. % % Note: Map scaling is to +/-max(abs(data); green = 0 % % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 4-28-1998 % -% See also: topoplot() +% See also: TOPOPLOT % Copyright (C) 4-28-98 from compmap.m Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license, added links -ad diff --git a/functions/miscfunc/compile_eeglab.m b/functions/miscfunc/compile_eeglab.m index 908d12c14..fa15626e9 100644 --- a/functions/miscfunc/compile_eeglab.m +++ b/functions/miscfunc/compile_eeglab.m @@ -6,19 +6,30 @@ % Copyright (C) 2009 Arnaud Delorme % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. disp('This function will compile EEGLAB in the output folder'); disp('provided below. You may also enter a path relative to the EEGLAB'); @@ -32,24 +43,24 @@ % deal with VisEd plugin (VisEd is both the name of the folder and the % function inside and this creates a problem path_vised = fileparts(which('VisEd')) -try, movefile( path_vised, [ path_vised '2' ]); catch, end; +try, movefile( path_vised, [ path_vised '2' ]); catch, end addpath([ path_vised '2' ]); path_fileio = fileparts(which('chantype')); -try, movefile( fullfile(path_fileio, '@uint64'), fullfile(path_fileio, 'uint64') ); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'buffer.m') , fullfile(path_fileio, 'private', 'bufferold.m') ); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'read_24bit.m') , fullfile(path_fileio, 'private', 'read_24bitold.m')); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'read_ctf_shm.m'), fullfile(path_fileio, 'private', 'read_ctf_shmold.m')); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'write_ctf_shm.m'), fullfile(path_fileio, 'private', 'write_ctf_shmold.m')); catch, end; +try, movefile( fullfile(path_fileio, '@uint64'), fullfile(path_fileio, 'uint64') ); catch, end +try, movefile( fullfile(path_fileio, 'private', 'buffer.m') , fullfile(path_fileio, 'private', 'bufferold.m') ); catch, end +try, movefile( fullfile(path_fileio, 'private', 'read_24bit.m') , fullfile(path_fileio, 'private', 'read_24bitold.m')); catch, end +try, movefile( fullfile(path_fileio, 'private', 'read_ctf_shm.m'), fullfile(path_fileio, 'private', 'read_ctf_shmold.m')); catch, end +try, movefile( fullfile(path_fileio, 'private', 'write_ctf_shm.m'), fullfile(path_fileio, 'private', 'write_ctf_shmold.m')); catch, end path_fileio = path_fileio(length(path_eeglab)+2:end); files_fileio = fullfile(path_fileio, '*.m'); files_fileio_private = fullfile(path_fileio, 'private', '*.m'); path_fieldtrip = fileparts(which('electroderealign')); addpath(fullfile(path_fieldtrip, 'public')); -try, movefile( fullfile(path_fieldtrip, 'fileio', '@uint64'), fullfile(path_fieldtrip, 'fileio', 'uint64') ); catch, end; -try, movefile( fullfile(path_fieldtrip, '@uint64'), fullfile(path_fieldtrip, 'uint64') ); catch, end; -try, movefile( fullfile(path_fieldtrip, 'topoplot.m'), fullfile(path_fieldtrip, 'topoplotold.m') ); catch, end; +try, movefile( fullfile(path_fieldtrip, 'fileio', '@uint64'), fullfile(path_fieldtrip, 'fileio', 'uint64') ); catch, end +try, movefile( fullfile(path_fieldtrip, '@uint64'), fullfile(path_fieldtrip, 'uint64') ); catch, end +try, movefile( fullfile(path_fieldtrip, 'topoplot.m'), fullfile(path_fieldtrip, 'topoplotold.m') ); catch, end path_fieldtrip = path_fieldtrip(length(path_eeglab)+2:end); files_fieldtrip = fullfile(path_fieldtrip, '*.m'); files_public = fullfile(path_fieldtrip, 'public', '*.m'); @@ -62,7 +73,7 @@ try rmpath('C:\Documents and Settings\delorme\My Documents\eeglab\plugins\editevents_arno'); -catch, end; +catch, end path_biosig = fileparts(which('install')); path_biosig = path_biosig(length(path_eeglab)+2:end); biosig = ' sopen.m sclose.m sread.m '; @@ -100,7 +111,7 @@ copyfile( 'eeglab', fullfile(outputfolder, 'eeglab'), 'f'); copyfile( 'eeglab', fullfile(outputfolder, 'eeglab'), 'f'); copyfile( 'eeglab.ctf', fullfile(outputfolder, 'eeglab.ctf'), 'f'); -end; +end % copy BESA files etc % ------------------- @@ -136,9 +147,9 @@ for index = 1:length(allfiles) tmpp = which(allfiles{index}); copyfile(tmpp, fullfile(outputfolder, 'help', allfiles{index})); -end; +end -% copy MCR file and visual C++ librairies +% copy MCR file and visual C++ libraries % --------------------------------------- if strcmpi(comp(1:2), 'PC') copyfile(fullfile(matlabroot, 'toolbox', 'compiler', 'deploy', 'win32', 'MCRInstaller.exe'), fullfile(outputfolder, 'MCRInstaller.exe')); @@ -160,7 +171,7 @@ fprintf(fid, 'echo To start EEGLAB in the future, simply click on the EEGLAB.EXE file\r\n'); fprintf(fid, 'eeglab.exe\r\n'); fclose(fid); - end; + end fid = fopen(fullfile(outputfolder, 'eeglab.exe.manifest'), 'w'); if fid == -1, disp('Error: cannot create manifest file'); else @@ -173,25 +184,25 @@ fprintf(fid, ' \r\n'); fprintf(fid, '\r\n'); fclose(fid); - end; -end; + end +end % cleaning up % ----------- -try, movefile( [ path_vised '2' ], path_vised); catch, end; -try, movefile( fullfile(path_fileio, 'uint64'), fullfile(path_fileio, '@uint64') ); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'bufferold.m') , fullfile(path_fileio, 'private', 'buffer.m') ); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'read_24bitold.m') , fullfile(path_fileio, 'private', 'read_24bit.m')); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'read_ctf_shmold.m'), fullfile(path_fileio, 'private', 'read_ctf_shm.m')); catch, end; -try, movefile( fullfile(path_fileio, 'private', 'write_ctf_shmold.m'), fullfile(path_fileio, 'private', 'write_ctf_shm.m')); catch, end; -try, movefile( fullfile(path_fieldtrip, 'fileio', 'uint64'), fullfile(path_fieldtrip, 'fileio', '@uint64') ); catch, end; -try, movefile( fullfile(path_fieldtrip, 'uint64'), fullfile(path_fieldtrip, '@uint64') ); catch, end; -try, movefile( fullfile(path_fieldtrip, 'topoplotold.m'), fullfile(path_fieldtrip, 'topoplot.m') ); catch, end; +try, movefile( [ path_vised '2' ], path_vised); catch, end +try, movefile( fullfile(path_fileio, 'uint64'), fullfile(path_fileio, '@uint64') ); catch, end +try, movefile( fullfile(path_fileio, 'private', 'bufferold.m') , fullfile(path_fileio, 'private', 'buffer.m') ); catch, end +try, movefile( fullfile(path_fileio, 'private', 'read_24bitold.m') , fullfile(path_fileio, 'private', 'read_24bit.m')); catch, end +try, movefile( fullfile(path_fileio, 'private', 'read_ctf_shmold.m'), fullfile(path_fileio, 'private', 'read_ctf_shm.m')); catch, end +try, movefile( fullfile(path_fileio, 'private', 'write_ctf_shmold.m'), fullfile(path_fileio, 'private', 'write_ctf_shm.m')); catch, end +try, movefile( fullfile(path_fieldtrip, 'fileio', 'uint64'), fullfile(path_fieldtrip, 'fileio', '@uint64') ); catch, end +try, movefile( fullfile(path_fieldtrip, 'uint64'), fullfile(path_fieldtrip, '@uint64') ); catch, end +try, movefile( fullfile(path_fieldtrip, 'topoplotold.m'), fullfile(path_fieldtrip, 'topoplot.m') ); catch, end return %histforexe(allfiles1, 'help'); -% help for lisence +% help for license % diff --git a/functions/miscfunc/compmap.m b/functions/miscfunc/compmap.m index b791af4fc..329326b4c 100644 --- a/functions/miscfunc/compmap.m +++ b/functions/miscfunc/compmap.m @@ -1,4 +1,4 @@ -% compmap() - Plot multiple topoplot() maps of ICA component topographies +% COMPMAP - Plot multiple TOPOPLOT maps of ICA component topographies % Click on an individual map to view separately. % Usage: % >> compmap (winv,'eloc_file',compnos,'title',rowscols,labels,printflag) @@ -25,25 +25,36 @@ % % Author: Colin Humphries, CNL / Salk Institute, Aug, 1996 % -% See also: topoplot() +% See also: TOPOPLOT -% This function calls topoplot(). and cbar(). +% This function calls TOPOPLOT. and CBAR. % Copyright (C) Colin Humphries & Scott Makeig, CNL / Salk Institute, Aug, 1996 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % Colin Humphries, CNL / Salk Institute, Aug, 1996 % 03-97 revised -CH @@ -51,19 +62,19 @@ % improved help msg; added figure offsets -Scott Makeig & CH % 11-13-97 fixed compnos<0 bug -sm % 11-18-97 added test for labels=comps -sm -% 12-08-97 added test for colorbar_tp() -sm +% 12-08-97 added test for COLORBAR_TP -sm % 12-15-97 added axis('square'), see SQUARE below -sm % 03-09-98 added test for eloc_file, fixed size checking for labels -sm % 02-09-00 added test for ' ' for srclabels(1,1) -sm % 02-23-00 added srclabels==' ' -> no labels -sm -% 03-16-00 added axcopy() -sm & tpj +% 03-16-00 added AXCOPY -sm & tpj % 02-25-01 added test for max(compnos) -sm % 05-24-01 added HEADPLOT logical flag below -sm % 01-25-02 reformated help & license -ad % NOTE: -% There is a minor problem with the Matlab function colorbar(). -% Use the toolbox cbar() instead. +% There is a minor problem with the Matlab function COLORBAR. +% Use the toolbox CBAR instead. function compmap(Winv,eloc_file,compnos,titleval,pagesize,srclabels,printlabel,caxis) @@ -171,12 +182,12 @@ function compmap(Winv,eloc_file,compnos,titleval,pagesize,srclabels,printlabel,c totalsources = length(compnos); if ~isempty(srclabels) - if ~ischar(srclabels(1,1)) | srclabels(1,1)==' ' % if numbers + if ~ischar(srclabels(1,1)) || srclabels(1,1)==' ' % if numbers if size(srclabels,1) == 1 srclabels = srclabels'; end end - if size(srclabels,1)==1 & size(srclabels,2)==1 & srclabels==' ' + if size(srclabels,1)==1 && size(srclabels,2)==1 && srclabels==' ' srclabels = repmat(srclabels,totalsources,1); end if size(srclabels,1) ~= totalsources, diff --git a/functions/miscfunc/compplot.m b/functions/miscfunc/compplot.m index 4e296e21b..bf990c0ab 100644 --- a/functions/miscfunc/compplot.m +++ b/functions/miscfunc/compplot.m @@ -1,4 +1,4 @@ -% compplot() - plot a data epoch and maps its scalp topography at a given time +% COMPPLOT - plot a data epoch and maps its scalp topography at a given time % % Usage: To plot the projection of an ICA component onto the scalp % >> projdata = icaproj(data,weights,compindex); @@ -9,8 +9,8 @@ % >> compplot(data,plotframe,chan_file,xstart,srate,title, splinefile); % % Inputs: -% data = data returned from icaproj() *ELSE* any EEG/ERP data epoch -% plotframe = frame to plot topographically {default|0 -> frame of max(var())} +% data = data returned from ICAPROJ *ELSE* any EEG/ERP data epoch +% plotframe = frame to plot topographically {default|0 -> frame of max(VAR)} % 'chan_file' = chan file, see >> topoplot example {def|0 -> 'chan_file'} % xstart = start time in seconds {default|0 -> 0} % srate = data sampling rate in Hz {default|0 -> 256 Hz} @@ -19,31 +19,42 @@ % % Authors: Colin Humphries & Scott Makeig, SCCN/INC/UCSD, CNL / Salk Institute, 1997 % -% See also: icaproj() +% See also: ICAPROJ % Copyright (C) 2000 Colin Humphries & Scott Makeig, SCCN/INC/UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 6-07-97 changed order of args in icaproj above -sm % Revised for Matlab 5.0.0.4064 11/97 -ch & sm -% 2-18-98 added undocumented headplot() option -sm +% 2-18-98 added undocumented HEADPLOT option -sm % 3-09-98 added check for chan_file -sm % 3-18-98 use new eegplot('noui') -sm % 7-25-98 make sure length(hkids) >= 3 on line 122 ff -sm -% 12-19-00 updated icaproj() call in help msg -sm +% 12-19-00 updated ICAPROJ call in help msg -sm % 1-24-01 corrected input error in header -ad % 01-25-02 reformated help & license, added links -ad diff --git a/functions/miscfunc/compsort.m b/functions/miscfunc/compsort.m index c96b07be2..d1381da26 100644 --- a/functions/miscfunc/compsort.m +++ b/functions/miscfunc/compsort.m @@ -1,4 +1,4 @@ -% compsort() - reorder ICA components, first largest to smallest by the size +% COMPSORT - reorder ICA components, first largest to smallest by the size % of their maximum variance in the single-component projections, % then (if specified) the nlargest component projections are % reordered by the (within-epoch) time point at which they reach @@ -9,12 +9,12 @@ % = compsort(data,weights,sphere,datamean, ... % frames,nlargest,chanlist); % Inputs: -% data = (chans,frames*epochs) the input data set decomposed by runica() -% weights = ica weight matrix returned by runica() -% sphere = sphering matrix returned by runica() +% data = (chans,frames*epochs) the input data set decomposed by RUNICA +% weights = ica weight matrix returned by RUNICA +% sphere = sphering matrix returned by RUNICA % % Optional: -% datamean = means removed from each row*epoch in runica() +% datamean = means removed from each row*epoch in RUNICA % (Note: 0 -> input data means are distributed among components % : 1 -> input data means are removed from the components (default)) % frames = frames per epoch in data (0 -> all) @@ -31,31 +31,42 @@ % % Authors: Scott Makeig, SCCN/INC/UCSD, La Jolla, 1996 % -% See also: runica() +% See also: RUNICA % Copyright (C) 1996 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 11-30-96 as compsort.m % 12-19-96 moved def of epochs below default frames def -sm % 02-18-97 added chanlist -sm -% 03-11-97 added default chanlist=0 -> all chans, fixed datamean and var() -sm +% 03-11-97 added default chanlist=0 -> all chans, fixed datamean and VAR -sm % 03-17-97 made nlargest default -> nlargest=0 -sm % 04-03-97 fixed problems and removed permweights, permcomps outputs -sm -% 04-04-97 shortened name to compsort() -sm +% 04-04-97 shortened name to COMPSORT -sm % 06-05-97 corrected variance computation -sm % 06-07-97 changed order of args to conform to runica -sm % 06-10-97 fixed recent bug in maxvar order -sm @@ -75,7 +86,7 @@ if framestot==0, fprintf('Gcompsort(): cannot process an empty data array.\n'); return -end; +end [srows,scols] = size(sphere); [wrows,wcols] = size(weights); @@ -85,7 +96,7 @@ if chanlist==0, chanlist = [1:chans]; end -if length(chanlist)~=chans & wrows 0 & indexA <= length(A) + if indexA > 0 && indexA <= length(A) R(index) = R(index) + B(indexB)*A(indexA); sumconvo = sumconvo + B(indexB); - end; - end; + end + end R(index) = R(index) / sumconvo; -end; +end return; diff --git a/functions/miscfunc/corrimage.m b/functions/miscfunc/corrimage.m index 3562c5f76..7f4f685ac 100755 --- a/functions/miscfunc/corrimage.m +++ b/functions/miscfunc/corrimage.m @@ -1,4 +1,4 @@ -% corrimage() - compute correlation image between an event and amplitude +% CORRIMAGE - compute correlation image between an event and amplitude % and phase in the time-frequency domain. % % Usage: @@ -32,14 +32,14 @@ % to retain. i.e. [5 95] remove the 5 lowest and highest % percentile of sortvar values (and associated data) before % computing statistics. Default is [0 100]. -% 'align' - [float] same as 'align' parameter of erpimage(). This -% parameter is used to contrain the 'times' parameter so +% 'align' - [float] same as 'align' parameter of ERPIMAGE. This +% parameter is used to constrain the 'times' parameter so % correlation with data trials containing 0-values (as a % result of data alignment) are avoided: computing these % correlations would produce spurious significant results. % Default is no alignment. -% 'method' - ['erpimage'|timefreq'] use either the erpimage() function -% of the timefreq() function to compute spectral decomposition. +% 'method' - ['erpimage'|timefreq'] use either the ERPIMAGE function +% of the TIMEFREQ function to compute spectral decomposition. % Default is 'timefreq' for speed reasons (note that both % methods should return the same results). % 'erpout' - [min max] regress out ERP using the selected time-window [min @@ -85,34 +85,45 @@ % Author: Arnaud Delorme & Scott Makeig, SCCN UCSD, % and CNL Salk Institute, 18 April 2003 % -% See also: erpimage() +% See also: ERPIMAGE %123456789012345678901234567890123456789012345678901234567890123456789012 % Copyright (C) 2002 Arnaud Delorme % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [time, freq, alpha, sigout, limits, tf, sortvar] = corrimage(data, sortvar, timevect, varargin) if nargin < 3 help corrimage; return; -end; +end -if isempty(timevect), timevect = [1 2]; end; +if isempty(timevect), timevect = [1 2]; end % check inputs % ------------ @@ -134,7 +145,7 @@ 'erpout' 'real' [] []; 'tfopt' 'cell' [] {}; 'erpimopt' 'cell' [] {} }); -if isstr(g), error(g); end; +if ischar(g), error(g); end fprintf('Generating %d frequencies in log scale (ignore message on linear scale)\n', g.freqs(2)); g.freqs = logscale(g.freqs(1), g.freqs(3), g.freqs(2)); @@ -142,7 +153,7 @@ frames = length(timevect); if size(data,1) == 1 data = reshape(data, frames, size(data,2)*size(data,3)/frames); -end; +end % trim sortvar values % ------------------- @@ -153,10 +164,10 @@ highindex = round(len*g.trim(2)/100); sortvar = sortvar(lowindex:highindex); data = data(:, lowindex:highindex); -if lowindex ~=1 | highindex ~= length(sortorder) +if lowindex ~=1 || highindex ~= length(sortorder) fprintf('Actual percentiles %1.2f-%1.2f (indices 1-%d -> %d-%d): event vals min %3.2f; max %3.2f\n', ... 100*(lowindex-1)/len, 100*highindex/len, len, lowindex, highindex, min(sortvar), max(sortvar)); -end; +end % assign subject number for each trial % ------------------------------------ @@ -164,10 +175,10 @@ alltrials = zeros(1,len); for index = 1:length(g.triallimit)-1 alltrials([g.triallimit(index):g.triallimit(index+1)-1]) = index; - end; + end alltrials = alltrials(sortorder); alltrials = alltrials(lowindex:highindex); -end; +end %figure; hist(sortvar) @@ -189,13 +200,13 @@ % compute shifts % -------------- shifts = round((g.align-sortvar)*srate/1000); % shifts can be positive or negative - end; + end %figure; hist(shifts) minshift = min(shifts); % negative maxshift = max(shifts); % positive - if minshift > 0, error('minshift has to be negative'); end; - if maxshift < 0, error('maxshift has to be positive'); end; + if minshift > 0, error('minshift has to be negative'); end + if maxshift < 0, error('maxshift has to be positive'); end % realign data for all trials % --------------------------- @@ -211,7 +222,7 @@ end end % end trial data = aligndata(maxshift+1:frames+minshift,:); - if any(any(isnan(data))), error('NaNs remaining after data alignment'); end; + if any(any(isnan(data))), error('NaNs remaining after data alignment'); end timevect = timevect(maxshift+1:frames+minshift); % take the time vector subset @@ -220,7 +231,7 @@ else fprintf('Time vector truncated for data alignment between %1.0f and %1.0f\n', ... min(timevect), max(timevect)); end; -end; +end % regress out the ERP from the data (4 times to have residual ERP close to 0) % --------------------------------------------------------------------------- @@ -243,8 +254,8 @@ fprintf([ '***********************************************\n' ... 'Ratio in ERP after regression (compare to before) is %3.2f\n' ... '***********************************************\n' ], mean(erpend./erpstart)); - end; - end; + end + end erpend = mean(data,2); fprintf([ '***********************************************\n' ... 'Ratio in grand ERP after regression (compare to before) is %3.2f\n' ... @@ -273,7 +284,7 @@ subplot(3,5,index); trials = find(alltrials == index); erpimage(data(:,trials), sortvar(trials), timevect, '', 50, 100, 'erp'); - end; + end disp('Regressing out ERP'); if ~isempty(g.triallimit) @@ -295,12 +306,12 @@ %data(:,trials) = erpregout(data(:,trials), [timevect(1) timevect(end)], g.erpout); %data(:,trials) = erpregout(data(:,trials), [timevect(1) timevect(end)], g.erpout); %data(:,trials) = erpregout(data(:,trials), [timevect(1) timevect(end)], g.erpout); - end; + end else %data = erpregout(data, [timevect(1) timevect(end)], g.erpout); - end; - end; -end; + end + end +end % generate time points % -------------------- @@ -309,16 +320,16 @@ % time frequency decomposition % ---------------------------- -if strcmpi(g.method, 'timefreq') & isempty(g.plotvals) +if strcmpi(g.method, 'timefreq') && isempty(g.plotvals) data = reshape(data, length(data)/length(sortvar), length(sortvar)); [tf, g.freqs, g.times] = timefreq(data, srate, 'freqs', g.freqs, 'timesout', g.times, ... 'tlimits', [min(timevect) max(timevect)], 'wavelet', 3); outvar = sortvar; -end; +end % compute correlation % ------------------- -if strcmpi(g.mode, 'phase') & isempty(g.plotvals) +if strcmpi(g.mode, 'phase') && isempty(g.plotvals) for freq = 1:length(g.freqs) fprintf('Computing correlation with phase %3.2f Hz ----------------------\n', g.freqs(freq)); for time = 1:length(g.times) @@ -328,7 +339,7 @@ '', 0,0,g.erpimopt{:}, 'phasesort', [g.times(time) 0 g.freqs(freq)], 'noshow', 'yes'); else phsangls = angle( squeeze(tf(freq, time, :))' ); - end; + end % computing ITCs [ ITC(freq, time) alpha(freq, time) ] = ... @@ -340,8 +351,8 @@ %ITC(freq, time) = mean(cmplx); %alpha(freq,time) = bootstat(outvar/mean(outvar), exp(j*phsangls), 'res = mean(arg1 .* arg2)', ... % 'naccu', 100, 'vals', abs(ITC(freq, time)), 'distfit', 'norm'); - end; - end; + end + end sigout = ITC; elseif isempty(g.plotvals) for freq = 1:length(g.freqs) @@ -353,11 +364,11 @@ '', 0,0,g.erpimopt{:}, 'ampsort', [g.times(time) 0 g.freqs(freq)], 'noshow', 'yes'); else phsamp = abs(squeeze(tf(freq, time, :)))'; - end; + end % computing ITCs [ypred alpha(freq, time) Rsq slope(freq, time)] = myregress(outvar, 20*log10(phsamp)); - end; + end end; sigout = slope; else @@ -365,7 +376,7 @@ g.freqs = g.plotvals{2}; alpha = g.plotvals{3}; sigout = g.plotvals{4}; -end; +end % plot correlation % ---------------- @@ -375,15 +386,15 @@ sigoutplot = angle(sigout); else sigoutplot = abs(sigout); - end; + end else sigoutplot = sigout; - end; + end sigouttmp = sigoutplot; if strcmpi(g.smooth, 'on') tmpfilt = gauss2d(3,3,.3,.3); tmpfilt = tmpfilt/sum(sum(tmpfilt)); alpha = conv2(alpha, tmpfilt, 'same'); - end; + end % mask signal out if g.pmask > 0.5 @@ -398,17 +409,17 @@ sigouttmp = sigoutplot; indices = find( alpha(:) > g.pmask); sigouttmp(indices) = 0; - end; + end - if strcmpi(g.nofig, 'off'), figure; end; + if strcmpi(g.nofig, 'off'), figure; end switch g.plot case 'alpha', limits = plotfig(g.times, g.freqs, -log10(alpha), g); case 'sigout', limits = plotfigsim(g.times, g.freqs, sigoutplot, g); case { 'sigoutm' 'sigoutp' }, limits = plotfigsim(g.times, g.freqs, sigouttmp, g); case 'sigoutm2', limits = subplot(1,2,1); plotfigsim(g.times, g.freqs, sigoutplot, g); limits = subplot(1,2,2); plotfigsim(g.times, g.freqs, sigouttmp, g); - end; -end; + end +end time = g.times; freq = g.freqs; @@ -433,7 +444,7 @@ trim = timevar(2); if length(timevect)-2*round(trim/100*length(timevect)) < npoints npoints = length(timevect)-round(trim/100*length(timevect)); - end; + end fprintf('Generating %d times points trimmed by %1.1f percent\n', npoints, trim); timer = max(timevect) - min(timevect); maxt = max(timevect)-timer*trim/100; @@ -446,9 +457,9 @@ trim = timevar(2); len = length(timevect); trimtimevect = timevect(round(trim/100*len)+1:len-round(trim/100*len)); - fprintf('Subsampling by %d and triming data by %1.1f percent (%d points)\n', nsub, trim, round(trim/100*len)); + fprintf('Subsampling by %d and trimming data by %1.1f percent (%d points)\n', nsub, trim, round(trim/100*len)); val = trimtimevect(1:nsub:end); - end; + end else val = timevar; end; @@ -458,10 +469,10 @@ for index = 1:length(val) [dum ind] = min(abs(timevect-val(index))); val(index) = timevect(ind); - end; + end if length(val) < length(unique(val)) disp('Warning: duplicate times, reduce the number of output times'); - end; + end if all(oldval == val) disp('Debug msg: Time value unchanged by finding closest in data'); end; @@ -486,18 +497,18 @@ set(gca, 'yticklabel', num2str(freqs(1:4:end)', 3)) xlabel('Time (ms)'); ylabel('Freq (Hz)'); - if ~isempty(g.limits), caxis(g.limits); end; + if ~isempty(g.limits), caxis(g.limits); end limits = caxis; if ~isempty(g.vert) for vert = g.vert(:)' hold on; plot([vert vert], [0.001 500], 'k', 'linewidth', 2); - end; - end; + end + end if strcmpi(g.cbar,'on') cbar; - end; + end -% plot figure with symetrical phase +% plot figure with symmetrical phase % --------------------------------- function limits = plotfigsim(times, freqs, vals, g) icadefs; @@ -516,16 +527,16 @@ clim = max(abs(caxis)); limits = [-clim clim]; caxis(limits); - end; + end xlabel('Time (ms)'); ylabel('Freq (Hz)'); if ~isempty(g.vert) for vert = g.vert(:)' hold on; plot([vert vert], [0.01 500], 'k', 'linewidth', 2); - end; - end; + end + end if strcmpi(g.cbar,'on') cbar; - end; + end return; @@ -561,7 +572,7 @@ % accumulate 200 values % --------------------- alpha = 0.05; -if exist('accarray') ~= 1, accarray = NaN; end; +if exist('accarray') ~= 1, accarray = NaN; end [sigval accarray] = bootstat(outvar/mean(outvar), phsangls, 'res = mean(arg1 .* exp(arg2*complex(0,1)))', ... 'accarray', accarray, 'bootside', 'upper', 'alpha', alpha); text(-1300,-1600,sprintf('Threshold for significance at %d percent(naccu=200): %3.4f\n', alpha*100, sigval)); diff --git a/functions/miscfunc/covary.m b/functions/miscfunc/covary.m index be1053d0c..1de9cd6f7 100644 --- a/functions/miscfunc/covary.m +++ b/functions/miscfunc/covary.m @@ -1,4 +1,4 @@ -% covary() - For vectors, covary(X) returns the variance of X. +% COVARY - For vectors, covary(X) returns the variance of X. % For matrices, covary(X)is a row vector containing the % variance of each column of X. % @@ -12,19 +12,30 @@ % Copyright (C) 2000 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license -ad diff --git a/functions/miscfunc/crossfold.m b/functions/miscfunc/crossfold.m index b4b94a9c0..80e9de45f 100644 --- a/functions/miscfunc/crossfold.m +++ b/functions/miscfunc/crossfold.m @@ -1,4 +1,4 @@ -% crossf() - Returns estimates and plot of event-related coherence (ERC) changes +% CROSSF - Returns estimates and plot of event-related coherence (ERC) changes % between data from two input channels. The lower panel gives the % coherent phase difference between the processes. In this panel, for Ex. % -90 degrees (blue) means xdata leads ydata by a quarter cycle. @@ -60,32 +60,43 @@ % % Authors: Sigurd Enghoff & Scott Makeig, SCCN/INC/UCSD, La Jolla, 1998 % -% See also: timef() +% See also: TIMEF % Copyright (C) 8/1/98 Sigurd Enghoff & Scott Makeig, SCCN/INC/UCSD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 11-20-98 defined LINEWIDTH constant -sm % 04-01-99 made number of frequencies consistent -se % 06-29-99 fixed constant-Q freq indexing -se % 08-13-99 added cohangle plotting -sm % 08-20-99 made bootstrap more efficient -sm -% 08-24-99 allow nan values introduced by possible eventlock() preproc. -sm +% 08-24-99 allow nan values introduced by possible EVENTLOCK preproc. -sm % 03-16-00 added lead/lag interpretation to help msg - sm & eric visser -% 03-16-00 added axcopy() feature -sm & tpj +% 03-16-00 added AXCOPY feature -sm & tpj % 04-20-00 fixed Rangle sign for wavelets, added verts array -sm % 01-22-01 corrected help msg when nargin<2 -sm & arno delorme % 01-25-02 reformated help & license, added links -ad @@ -128,10 +139,10 @@ return end -if (min(size(X))~=1 | length(X)<2) +if (min(size(X))~=1 || length(X)<2) fprintf('crossf(): xdata must be a row or column vector.\n'); return -elseif (min(size(Y))~=1 | length(Y)<2) +elseif (min(size(Y))~=1 || length(Y)<2) fprintf('crossf(): ydata must be a row or column vector.\n'); return elseif (length(X) ~= length(Y)) @@ -141,7 +152,7 @@ if (nargin < 3) epoch = DEFAULT_EPOCH; -elseif (~isnumeric(epoch) | length(epoch)~=1 | epoch~=round(epoch)) +elseif (~isnumeric(epoch) || length(epoch)~=1 || epoch~=round(epoch)) fprintf('crossf(): Value of frames must be an integer.\n'); return elseif (epoch <= 0) @@ -154,7 +165,7 @@ if (nargin < 4) timelim = DEFAULT_TIMELIM; -elseif (~isnumeric(timelim) | sum(size(timelim))~=3) +elseif (~isnumeric(timelim) || sum(size(timelim))~=3) error('crossf(): Value of tlimits must be a vector containing two numbers.'); elseif (timelim(1) >= timelim(2)) error('crossf(): tlimits interval must be [min,max].'); @@ -168,7 +179,7 @@ if (nargin < 6) Fs = DEFAULT_FS; -elseif (~isnumeric(Fs) | length(Fs)~=1) +elseif (~isnumeric(Fs) || length(Fs)~=1) error('crossf(): Value of srate must be a number.'); elseif (Fs <= 0) error('crossf(): Value of srate must be positive.'); @@ -176,7 +187,7 @@ if (nargin < 7) varwin = DEFAULT_VARWIN; -elseif (~isnumeric(varwin) | length(varwin)~=1) +elseif (~isnumeric(varwin) || length(varwin)~=1) error('crossf(): Value of cycles must be a number.'); elseif (varwin < MAX_BASELN) error('crossf(): Value of cycles must be either zero or positive.'); @@ -184,11 +195,11 @@ if (nargin < 8) winsize = max(pow2(nextpow2(epoch)-3),4); -elseif (~isnumeric(winsize) | length(winsize)~=1 | winsize~=round(winsize)) +elseif (~isnumeric(winsize) || length(winsize)~=1 || winsize~=round(winsize)) error('crossf(): Value of winsize must be an integer number.'); elseif (winsize <= 0) error('crossf(): Value of winsize must be positive.'); -elseif (varwin == 0 & pow2(nextpow2(winsize)) ~= winsize) +elseif (varwin == 0 && pow2(nextpow2(winsize)) ~= winsize) error('crossf(): Value of winsize must be an integer power of two [1,2,4,8,16,...]'); elseif (winsize > epoch) error('crossf(): Value of winsize must be less than epoch length.'); @@ -196,7 +207,7 @@ if (nargin < 9) nwin = DEFAULT_NWIN; -elseif (~isnumeric(nwin) | length(nwin)~=1 | nwin~=round(nwin)) +elseif (~isnumeric(nwin) || length(nwin)~=1 || nwin~=round(nwin)) error('crossf(): Value of nwin must be an integer number.'); elseif (nwin <= 0) error('crossf(): Value of nwin must be positive.'); @@ -207,7 +218,7 @@ if (nargin < 10) oversmp = DEFAULT_OVERSMP; -elseif (~isnumeric(oversmp) | length(oversmp)~=1 | oversmp~=round(oversmp)) +elseif (~isnumeric(oversmp) || length(oversmp)~=1 || oversmp~=round(oversmp)) error('crossf(): Value of oversmp must be an integer number.'); elseif (oversmp <= 0) error('crossf(): Value of oversmp must be positive.'); @@ -217,7 +228,7 @@ if (nargin < 11) maxfreq = DEFAULT_MAXFREQ; -elseif (~isnumeric(maxfreq) | length(maxfreq)~=1) +elseif (~isnumeric(maxfreq) || length(maxfreq)~=1) error('crossf(): Value of maxfreq must be a number.'); elseif (maxfreq <= 0) error('crossf(): Value of maxfreq must be positive.'); @@ -225,9 +236,9 @@ if (nargin < 12) alpha = DEFAULT_ALPHA; -elseif (~isnumeric(alpha) | length(alpha)~=1) +elseif (~isnumeric(alpha) || length(alpha)~=1) error('crossf(): Value of alpha must be a number.'); -elseif (round(NACCU*alpha) < 2 | alpha > .5) +elseif (round(NACCU*alpha) < 2 || alpha > .5) fprintf('crossf(): Value of alpha must be in the range (~0,0.5]'); return else @@ -349,7 +360,7 @@ s = ceil(rand([1 2])*nwin); % random ints [1,nwin] tmpX = tmpsX(:,s(1)); tmpY = tmpsY(:,s(2)); - if ~any(isnan(tmpX)) & ~any(isnan(tmpY)) + if ~any(isnan(tmpX)) && ~any(isnan(tmpY)) RR = tmpX.*conj(tmpY) ./ (abs(tmpX).*abs(tmpY)); % complex coher. Rboot(:,j) = Rboot(:,j) + RR; j = j+1; @@ -431,7 +442,7 @@ plot([0 0],[0 freqs(max(dispf))],'--m','LineWidth',LINEWIDTH) for i=1:length(verts) plot([verts(i) verts(i)],[0 freqs(max(dispf))],'--m','LineWidth',LINEWIDTH); -end; +end hold off set(h(6),'YTickLabel',[],'YTick',[]) set(h(6),'XTickLabel',[],'XTick',[]) @@ -452,7 +463,7 @@ plot([0 0],[-500 500],'--m','LineWidth',LINEWIDTH); for i=1:length(verts) plot([verts(i) verts(i)],[-500 500],'--m','LineWidth',LINEWIDTH); -end; +end axis([min(times) max(times) 0 max(Emax)*1.2]) tick = get(h(10),'YTick'); set(h(10),'YTick',[tick(1) ; tick(length(tick))]) @@ -516,7 +527,7 @@ plot([0 0],[0 freqs(max(dispf))],'--m','LineWidth',LINEWIDTH); % zero-time line for i=1:length(verts) plot([verts(i) verts(i)],[0 freqs(max(dispf))],'--m','LineWidth',LINEWIDTH); - end; + end pos13 = get(h(13),'Position'); set(h(13),'Position',[pos13(1) pos13(2) midpos(3) pos13(4)]); diff --git a/functions/miscfunc/crossfreq.m b/functions/miscfunc/crossfreq.m index b236f9122..b29019d19 100644 --- a/functions/miscfunc/crossfreq.m +++ b/functions/miscfunc/crossfreq.m @@ -1,4 +1,4 @@ -% crossfreq() - compute cross-frequency coherences. Power of first input +% CROSSFREQ - compute cross-frequency coherences. Power of first input % correlation with phase of second. % % Usage: @@ -41,7 +41,7 @@ % 'wavelet2' = same as 'wavelet' for the second argument. Default is % same as cycles. Note that if the lowest frequency for X % and Y are different and cycle is [cycles expfactor], it -% may result in discrepencies in the number of cycles at +% may result in discrepancies in the number of cycles at % the same frequencies for X and Y. % 'ntimesout' = Number of output times (int> limits_vector = datlim(data); @@ -10,6 +10,33 @@ % % Author: Scott Makeig, SCCN/INC/UCSD, May 28, 2005 +% Copyright (C) Scott Makeig, SCCN/INC/UCSD, May 28, 2005 +% +% 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 [limits_vector] = datlim(data) if ~isnumeric(data) diff --git a/functions/miscfunc/del2map.m b/functions/miscfunc/del2map.m index ce3fd8726..4436ae6ec 100644 --- a/functions/miscfunc/del2map.m +++ b/functions/miscfunc/del2map.m @@ -1,4 +1,4 @@ -% del2map() - compute the discrete laplacian of an EEG distribution. +% DEL2MAP - compute the discrete laplacian of an EEG distribution. % % Usage: % >> [ laplac ] = del2map( map, filename, draw ); @@ -23,55 +23,66 @@ % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [ laplac, sumLaplac2D ] = del2map( map, filename, draw ) if nargin < 2 help del2map; return; -end; +end % process several maps if size(map,2) > 1 if size(map,1) > 1 for index = 1:size(map,2) laplac(:,index) = del2map( map(:,index), filename); - end; + end return; else map = map'; - end; -end; + end +end MAXCHANS = size(map,1); GRID_SCALE = 2*MAXCHANS+5; % Read the channel file % --------------------- -if ischar( filename ) | isstruct( filename ) +if ischar( filename ) || isstruct( filename ) [tmp lb Th Rd] = readlocs(filename); Th = pi/180*Th; % convert degrees to rads [x,y] = pol2cart(Th,Rd); else x = real(filename); y = imag(filename); - if exist('draw') == 1 & draw ~= 0 + if exist('draw') == 1 && draw ~= 0 line( [(x-0.01)' (x+0.01)']', [(y-0.01)' (y+0.01)']'); line( [(x+0.01)' (x-0.01)']', [(y-0.01)' (y+0.01)']'); - end; + end end; % locates nearest position of electrod in the grid @@ -81,7 +92,7 @@ for i=1:MAXCHANS [useless_var horizidx(i)] = min(abs(x(i) - xi)); % find pointers to electrode [useless_var vertidx(i)] = min(abs(y(i) - yi)); % positions in Zi -end; +end % Compute gradient % ---------------- @@ -96,16 +107,16 @@ % Draw gradient % ------------- - if exist('draw') == 1 & draw ~= 0 + if exist('draw') == 1 && draw ~= 0 if size(map,2) > 1 subplot(ceil(sqrt(size(map,2))), ceil(sqrt(size(map,2))), i); - end; + end plot(y, x, 'x', 'Color', 'black', 'markersize', 5); hold on contour(Xi, Yi, laplac2D); hold off; %line( [(x-0.01)' (x+0.01)']', [(y-0.01)' (y+0.01)']', 'Color','black'); %line( [(x+0.01)' (x-0.01)']', [(y-0.01)' (y+0.01)']', 'Color','black'); title( int2str(i) ); - end; + end end; % return; diff --git a/functions/miscfunc/dendhier.m b/functions/miscfunc/dendhier.m index d86ff87ed..cef7cef32 100644 --- a/functions/miscfunc/dendhier.m +++ b/functions/miscfunc/dendhier.m @@ -1,3 +1,4 @@ +function [links,topology,node] = dendhier(links,topology,node) % DENDHIER: Recursive algorithm to find links and distance coordinates on a % dendrogram, given the topology matrix. % @@ -12,7 +13,6 @@ % RE Strauss, 7/13/95 -function [links,topology,node] = dendhier(links,topology,node) n = size(topology,1)+1; % Number of OTUs c1 = topology(node,1); @@ -27,7 +27,7 @@ prevdist = topology(prevnode,4); links = [links; c1 clst prevdist dist]; [links,topology,node] = dendhier(links,topology,prevnode); - end; + end if (c2 <= n) links = [links; c2 clst 0 dist]; @@ -36,6 +36,6 @@ prevdist = topology(prevnode,4); links = [links; c2 clst prevdist dist]; [links,topology,node] = dendhier(links,topology,prevnode); - end; + end return; diff --git a/functions/miscfunc/dendplot.m b/functions/miscfunc/dendplot.m index 0283eed4a..1510d981b 100644 --- a/functions/miscfunc/dendplot.m +++ b/functions/miscfunc/dendplot.m @@ -1,3 +1,4 @@ +function dendplot(topology,labels,fontsize) % DENDPLOT: Plots a dendrogram given a topology matrix. % % Usage: dendplot(topology,{labels},{fontsize}) @@ -14,17 +15,16 @@ % RE Strauss, 5/27/98 % 8/20/99 - miscellaneous changes for Matlab v5 -function dendplot(topology,labels,fontsize) if (nargin<2) labels = []; - end; + end if (nargin < 3) fontsize = []; - end; + end if (isempty(fontsize)) % Default font size for labels fontsize = 10; - end; + end r = size(topology,1); n = r+1; % Number of taxa @@ -36,7 +36,7 @@ function dendplot(topology,labels,fontsize) y(otus) = 0.5:(n-0.5); for i = 1:(n-1) y(topology(i,3)) = mean([y(topology(i,1)),y(topology(i,2))]); - end; + end clf; % Begin plot hold on; @@ -47,14 +47,14 @@ function dendplot(topology,labels,fontsize) X = [links(i,3) links(i,4)]; Y = [y(desc) y(desc)]; plot(X,Y,'k'); - end; + end for i = (n+1):(2*n-1) % Vertical lines indx = find(links(:,2)==i); X = [links(indx,4)]; Y = [y(links(indx(1),1)) y(links(indx(2),1))]; plot(X,Y,'k'); - end; + end maxdist = max(links(:,4)); for i = 1:n % OTU labels @@ -65,8 +65,8 @@ function dendplot(topology,labels,fontsize) h = text(-.02*maxdist,y(i),num2str(i)); % For OTUs on right set(h,'fontsize',fontsize); % text(-.06*maxdist,y(i),num2str(i)); % For UTOs on left - end; - end; + end + end axis([0 maxdist+0.03*maxdist 0 n]); % Axes axis('square'); diff --git a/functions/miscfunc/detectmalware.m b/functions/miscfunc/detectmalware.m index 2fd0b3ef6..a758478c5 100644 --- a/functions/miscfunc/detectmalware.m +++ b/functions/miscfunc/detectmalware.m @@ -1,12 +1,39 @@ % this function detects potential malware in the current folder and subfolders % -% Author: A. Delorme, Cotober 2013 +% Author: A. Delorme, October 2013 + +% Copyright (C) Author: A. Delorme, October 2013 +% +% 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 detectmalware(currentFolder); if nargin < 1 currentFolder = pwd; -end; +end folderContent = dir(currentFolder); folderContent = { folderContent.name }; @@ -27,21 +54,21 @@ if length(str) > 1 && str(1) ~= '%' res = cellfun(@(x)~isempty(findstr(x, str)), malwareStrings(1:end-1)); - if str(1) == '!', res(end+1) = 1; end; + if str(1) == '!', res(end+1) = 1; end if any(res) pos = find(res); pos = pos(1); disp('************************************') fprintf('Potential malware command detected containing "%s" in\n %s line %d\n', malwareStrings{pos}, fullfile(currentFolder, currentFile), countLine); fprintf('%d: %s\n%d: %s\n%d: %s\n', countLine-1, prevstr, countLine, str, countLine+1, fgetl(fid)); countLine = countLine+1; - end; - end; + end + end prevstr = str; - end; + end fclose(fid); elseif exist(currentFile) == 7 && ~strcmpi(currentFile, '..') && ~strcmpi(currentFile, '.') detectmalware(fullfile(currentFolder, currentFile)); - end; -end; + end +end diff --git a/functions/miscfunc/difftopo.m b/functions/miscfunc/difftopo.m index 0486381d0..dba229881 100644 --- a/functions/miscfunc/difftopo.m +++ b/functions/miscfunc/difftopo.m @@ -19,30 +19,41 @@ % Copyright (C) Scott Makeig, SCCN/INC/UCSD 3/28/05 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 difftopo(ALLEEG,eeg1,eeg2,interval,limits,subcomps); if nargin < 3 help difftopo return end -if eeg1 < 1 | eeg1 > length(ALLEEG) +if eeg1 < 1 || eeg1 > length(ALLEEG) help difftopo return end -if eeg2 < 1 | eeg2 > length(ALLEEG) +if eeg2 < 1 || eeg2 > length(ALLEEG) help difftopo return end @@ -50,7 +61,7 @@ help difftopo return end -if ndims(ALLEEG(eeg1).data) ~=3 | ndims(ALLEEG(eeg2).data) ~=3 +if ndims(ALLEEG(eeg1).data) ~=3 || ndims(ALLEEG(eeg2).data) ~=3 error('EEG datasets must be epoched data'); end diff --git a/functions/miscfunc/dprime.m b/functions/miscfunc/dprime.m deleted file mode 100644 index fd8a47c2d..000000000 --- a/functions/miscfunc/dprime.m +++ /dev/null @@ -1,433 +0,0 @@ -% DPRIME - Signal-detection theory sensitivity measure. -% -% d = dprime(pHit,pFA) -% [d,beta] = dprime(pHit,pFA) -% -% PHIT and PFA are numerical arrays of the same shape. -% PHIT is the proportion of "Hits": P(Yes|Signal) -% PFA is the proportion of "False Alarms": P(Yes|Noise) -% All numbers involved must be between 0 and 1. -% The function calculates the d-prime measure for each pair. -% The criterion value BETA can also be requested. -% Requires MATLAB's Statistical Toolbox. -% -% References: -% * Green, D. M. & Swets, J. A. (1974). Signal Detection Theory and -% Psychophysics (2nd Ed.). Huntington, NY: Robert Krieger Publ.Co. -% * Macmillan, Neil A. & Creelman, C. Douglas (2005). Detection Theory: -% A User's Guide (2nd Ed.). Lawrence Erlbaum Associates. -% -% See also NORMINV, NORMPDF. - -% Original coding by Alexander Petrov, Ohio State University. -% $Revision: 1.2 $ $Date: 2009-02-09 10:49:29 $ -% -% Part of the utils toolbox version 1.1 for MATLAB version 5 and up. -% http://alexpetrov.com/softw/utils/ -% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com -% Please read the LICENSE and NO WARRANTY statement: - -% GNU Public License for the UTILS Toolbox -% -% ============================================================================== -% -% IN BRIEF -% ======== -% -% This document refers to all Matlab scripts and documentation (referred -% to collectively here as "the software") contained in the "utils toolbox" -% by Alexander Petrov 1999-2006, http://alexpetrov.com/softw/utils/ -% -% The software is freely available and freely redistributable, according -% to the conditions of the Gnu General Public License (below). You may not -% distribute the software, in whole or in part, in conjunction with -% proprietary code. That means you ONLY have my permission to distribute a -% program that uses my code IF you also make freely available (under the -% terms of the Gnu GPL) the source code for your whole project. You may -% not pass on the software to another party in its current form or any -% altered, embellished or reduced form, without acknowledging the author -% and including a copy of this license. -% -% The software is distributed in the hope that it will be useful, but -% WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -% Public License (reproduced below), and the Free Software Foundation -% website (http://www.fsf.org) for more details. -% -% Please notify the author, via the website, of any bugs, notes, comments -% or suggested changes, particularly of any useful changes you may have -% made to your own copy of the software. -% -% Alex Petrov, December 2006 -% -% ============================================================================== -% -% GNU GENERAL PUBLIC LICENSE -% ========================== -% -% Version 2, June 1991 -% Copyright (C) 1989, 1991 Free Software Foundation, Inc. -% 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -% Everyone is permitted to copy and distribute verbatim copies -% of this license document, but changing it is not allowed. -% -% -% Preamble -% ======== -% -% The licenses for most software are designed to take away your -% freedom to share and change it. By contrast, the GNU General Public -% License is intended to guarantee your freedom to share and change free -% software--to make sure the software is free for all its users. This -% General Public License applies to most of the Free Software -% Foundation's software and to any other program whose authors commit to -% using it. (Some other Free Software Foundation software is covered by -% the GNU Library General Public License instead.) You can apply it to -% your programs, too. -% -% When we speak of free software, we are referring to freedom, not -% price. Our General Public Licenses are designed to make sure that you -% have the freedom to distribute copies of free software (and charge for -% this service if you wish), that you receive source code or can get it -% if you want it, that you can change the software or use pieces of it -% in new free programs; and that you know you can do these things. -% -% To protect your rights, we need to make restrictions that forbid -% anyone to deny you these rights or to ask you to surrender the rights. -% These restrictions translate to certain responsibilities for you if you -% distribute copies of the software, or if you modify it. -% -% For example, if you distribute copies of such a program, whether -% gratis or for a fee, you must give the recipients all the rights that -% you have. You must make sure that they, too, receive or can get the -% source code. And you must show them these terms so they know their -% rights. -% -% We protect your rights with two steps: (1) copyright the software, and -% (2) offer you this license which gives you legal permission to copy, -% distribute and/or modify the software. -% -% Also, for each author's protection and ours, we want to make certain -% that everyone understands that there is no warranty for this free -% software. If the software is modified by someone else and passed on, we -% want its recipients to know that what they have is not the original, so -% that any problems introduced by others will not reflect on the original -% authors' reputations. -% -% Finally, any free program is threatened constantly by software -% patents. We wish to avoid the danger that redistributors of a free -% program will individually obtain patent licenses, in effect making the -% program proprietary. To prevent this, we have made it clear that any -% patent must be licensed for everyone's free use or not licensed at all. -% -% The precise terms and conditions for copying, distribution and -% modification follow. -% -% -% GNU GENERAL PUBLIC LICENSE -% ========================== -% TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -% =============================================================== -% -% 0. This License applies to any program or other work which contains -% a notice placed by the copyright holder saying it may be distributed -% under the terms of this General Public License. The "Program", below, -% refers to any such program or work, and a "work based on the Program" -% means either the Program or any derivative work under copyright law: -% that is to say, a work containing the Program or a portion of it, -% either verbatim or with modifications and/or translated into another -% language. (Hereinafter, translation is included without limitation in -% the term "modification".) Each licensee is addressed as "you". -% -% Activities other than copying, distribution and modification are not -% covered by this License; they are outside its scope. The act of -% running the Program is not restricted, and the output from the Program -% is covered only if its contents constitute a work based on the -% Program (independent of having been made by running the Program). -% Whether that is true depends on what the Program does. -% -% 1. You may copy and distribute verbatim copies of the Program's -% source code as you receive it, in any medium, provided that you -% conspicuously and appropriately publish on each copy an appropriate -% copyright notice and disclaimer of warranty; keep intact all the -% notices that refer to this License and to the absence of any warranty; -% and give any other recipients of the Program a copy of this License -% along with the Program. -% -% You may charge a fee for the physical act of transferring a copy, and -% you may at your option offer warranty protection in exchange for a fee. -% -% 2. You may modify your copy or copies of the Program or any portion -% of it, thus forming a work based on the Program, and copy and -% distribute such modifications or work under the terms of Section 1 -% above, provided that you also meet all of these conditions: -% -% a) You must cause the modified files to carry prominent notices -% stating that you changed the files and the date of any change. -% -% b) You must cause any work that you distribute or publish, that in -% whole or in part contains or is derived from the Program or any -% part thereof, to be licensed as a whole at no charge to all third -% parties under the terms of this License. -% -% c) If the modified program normally reads commands interactively -% when run, you must cause it, when started running for such -% interactive use in the most ordinary way, to print or display an -% announcement including an appropriate copyright notice and a -% notice that there is no warranty (or else, saying that you provide -% a warranty) and that users may redistribute the program under -% these conditions, and telling the user how to view a copy of this -% License. (Exception: if the Program itself is interactive but -% does not normally print such an announcement, your work based on -% the Program is not required to print an announcement.) -% -% These requirements apply to the modified work as a whole. If -% identifiable sections of that work are not derived from the Program, -% and can be reasonably considered independent and separate works in -% themselves, then this License, and its terms, do not apply to those -% sections when you distribute them as separate works. But when you -% distribute the same sections as part of a whole which is a work based -% on the Program, the distribution of the whole must be on the terms of -% this License, whose permissions for other licensees extend to the -% entire whole, and thus to each and every part regardless of who wrote it. -% -% Thus, it is not the intent of this section to claim rights or contest -% your rights to work written entirely by you; rather, the intent is to -% exercise the right to control the distribution of derivative or -% collective works based on the Program. -% -% In addition, mere aggregation of another work not based on the Program -% with the Program (or with a work based on the Program) on a volume of -% a storage or distribution medium does not bring the other work under -% the scope of this License. -% -% 3. You may copy and distribute the Program (or a work based on it, -% under Section 2) in object code or executable form under the terms of -% Sections 1 and 2 above provided that you also do one of the following: -% -% a) Accompany it with the complete corresponding machine-readable -% source code, which must be distributed under the terms of Sections -% 1 and 2 above on a medium customarily used for software interchange; or, -% -% b) Accompany it with a written offer, valid for at least three -% years, to give any third party, for a charge no more than your -% cost of physically performing source distribution, a complete -% machine-readable copy of the corresponding source code, to be -% distributed under the terms of Sections 1 and 2 above on a medium -% customarily used for software interchange; or, -% -% c) Accompany it with the information you received as to the offer -% to distribute corresponding source code. (This alternative is -% allowed only for noncommercial distribution and only if you -% received the program in object code or executable form with such -% an offer, in accord with Subsection b above.) -% -% The source code for a work means the preferred form of the work for -% making modifications to it. For an executable work, complete source -% code means all the source code for all modules it contains, plus any -% associated interface definition files, plus the scripts used to -% control compilation and installation of the executable. However, as a -% special exception, the source code distributed need not include -% anything that is normally distributed (in either source or binary -% form) with the major components (compiler, kernel, and so on) of the -% operating system on which the executable runs, unless that component -% itself accompanies the executable. -% -% If distribution of executable or object code is made by offering -% access to copy from a designated place, then offering equivalent -% access to copy the source code from the same place counts as -% distribution of the source code, even though third parties are not -% compelled to copy the source along with the object code. -% -% 4. You may not copy, modify, sublicense, or distribute the Program -% except as expressly provided under this License. Any attempt -% otherwise to copy, modify, sublicense or distribute the Program is -% void, and will automatically terminate your rights under this License. -% However, parties who have received copies, or rights, from you under -% this License will not have their licenses terminated so long as such -% parties remain in full compliance. -% -% 5. You are not required to accept this License, since you have not -% signed it. However, nothing else grants you permission to modify or -% distribute the Program or its derivative works. These actions are -% prohibited by law if you do not accept this License. Therefore, by -% modifying or distributing the Program (or any work based on the -% Program), you indicate your acceptance of this License to do so, and -% all its terms and conditions for copying, distributing or modifying -% the Program or works based on it. -% -% 6. Each time you redistribute the Program (or any work based on the -% Program), the recipient automatically receives a license from the -% original licensor to copy, distribute or modify the Program subject to -% these terms and conditions. You may not impose any further -% restrictions on the recipients' exercise of the rights granted herein. -% You are not responsible for enforcing compliance by third parties to -% this License. -% -% 7. If, as a consequence of a court judgment or allegation of patent -% infringement or for any other reason (not limited to patent issues), -% conditions are imposed on you (whether by court order, agreement or -% otherwise) that contradict the conditions of this License, they do not -% excuse you from the conditions of this License. If you cannot -% distribute so as to satisfy simultaneously your obligations under this -% License and any other pertinent obligations, then as a consequence you -% may not distribute the Program at all. For example, if a patent -% license would not permit royalty-free redistribution of the Program by -% all those who receive copies directly or indirectly through you, then -% the only way you could satisfy both it and this License would be to -% refrain entirely from distribution of the Program. -% -% If any portion of this section is held invalid or unenforceable under -% any particular circumstance, the balance of the section is intended to -% apply and the section as a whole is intended to apply in other -% circumstances. -% -% It is not the purpose of this section to induce you to infringe any -% patents or other property right claims or to contest validity of any -% such claims; this section has the sole purpose of protecting the -% integrity of the free software distribution system, which is -% implemented by public license practices. Many people have made -% generous contributions to the wide range of software distributed -% through that system in reliance on consistent application of that -% system; it is up to the author/donor to decide if he or she is willing -% to distribute software through any other system and a licensee cannot -% impose that choice. -% -% This section is intended to make thoroughly clear what is believed to -% be a consequence of the rest of this License. -% -% 8. If the distribution and/or use of the Program is restricted in -% certain countries either by patents or by copyrighted interfaces, the -% original copyright holder who places the Program under this License -% may add an explicit geographical distribution limitation excluding -% those countries, so that distribution is permitted only in or among -% countries not thus excluded. In such case, this License incorporates -% the limitation as if written in the body of this License. -% -% 9. The Free Software Foundation may publish revised and/or new versions -% of the General Public License from time to time. Such new versions will -% be similar in spirit to the present version, but may differ in detail to -% address new problems or concerns. -% -% Each version is given a distinguishing version number. If the Program -% specifies a version number of this License which applies to it and "any -% later version", you have the option of following the terms and conditions -% either of that version or of any later version published by the Free -% Software Foundation. If the Program does not specify a version number of -% this License, you may choose any version ever published by the Free Software -% Foundation. -% -% 10. If you wish to incorporate parts of the Program into other free -% programs whose distribution conditions are different, write to the author -% to ask for permission. For software which is copyrighted by the Free -% Software Foundation, write to the Free Software Foundation; we sometimes -% make exceptions for this. Our decision will be guided by the two goals -% of preserving the free status of all derivatives of our free software and -% of promoting the sharing and reuse of software generally. -% -% NO WARRANTY: -% -% 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -% FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -% OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -% PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -% OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -% TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -% PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -% REPAIR OR CORRECTION. -% -% 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -% WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -% REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -% INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -% OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -% TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -% YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -% PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -% POSSIBILITY OF SUCH DAMAGES. -% -% END OF TERMS AND CONDITIONS -% -% -% How to Apply These Terms to Your New Programs -% ============================================= -% -% If you develop a new program, and you want it to be of the greatest -% possible use to the public, the best way to achieve this is to make it -% free software which everyone can redistribute and change under these terms. -% -% To do so, attach the following notices to the program. It is safest -% to attach them to the start of each source file to most effectively -% convey the exclusion of warranty; and each file should have at least -% the "copyright" line and a pointer to where the full notice is found. -% -% -% Copyright (C) -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -% -% -% Also add information on how to contact you by electronic and paper mail. -% -% If the program is interactive, make it output a short notice like this -% when it starts in an interactive mode: -% -% Gnomovision version 69, Copyright (C) year name of author -% Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. -% This is free software, and you are welcome to redistribute it -% under certain conditions; type `show c' for details. -% -% The hypothetical commands `show w' and `show c' should show the appropriate -% parts of the General Public License. Of course, the commands you use may -% be called something other than `show w' and `show c'; they could even be -% mouse-clicks or menu items--whatever suits your program. -% -% You should also get your employer (if you work as a programmer) or your -% school, if any, to sign a "copyright disclaimer" for the program, if -% necessary. Here is a sample; alter the names: -% -% Yoyodyne, Inc., hereby disclaims all copyright interest in the program -% `Gnomovision' (which makes passes at compilers) written by James Hacker. -% -% , 1 April 1989 -% Ty Coon, President of Vice -% -% This General Public License does not permit incorporating your program into -% proprietary programs. If your program is a subroutine library, you may -% consider it more useful to permit linking proprietary applications with the -% library. If this is what you want to do, use the GNU Library General -% Public License instead of this License. -% -% ============================================================================== - -function [d,beta] = dprime(pHit,pFA) - -%-- Convert to Z scores, no error checking -zHit = norminv(pHit) ; -zFA = norminv(pFA) ; - -%-- Calculate d-prime -d = zHit - zFA ; - -%-- If requested, calculate BETA -if (nargout > 1) - yHit = normpdf(zHit) ; - yFA = normpdf(zFA) ; - beta = yHit ./ yFA ; -end - -%% Return DPRIME and possibly BETA -%%%%%% End of file DPRIME.M diff --git a/functions/miscfunc/eeg_ms2f.m b/functions/miscfunc/eeg_ms2f.m index ddfa38ca2..b22581939 100644 --- a/functions/miscfunc/eeg_ms2f.m +++ b/functions/miscfunc/eeg_ms2f.m @@ -1,4 +1,4 @@ -% eeg_ms2f() - convert epoch latency in ms to nearest epoch frame number +% EEG_MS2F - convert epoch latency in ms to nearest epoch frame number % % Usage: % >> outf = eeg_ms2f(EEG,ms); @@ -10,11 +10,38 @@ % % Author: Scott Makeig, SCCN/INC, 12/05 +% Copyright (C) Scott Makeig, SCCN/INC, 12/05 +% +% 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 outf = eeg_ms2f(EEG,ms) - ms = ms/1000; - if ms < EEG.xmin | ms > EEG.xmax - error('time out of range'); - end - outf = 1+round((EEG.pnts-1)*(ms-EEG.xmin)/(EEG.xmax-EEG.xmin)); - % else - % [tmp outf] = min(abs(EEG.times-ms)); +ms = ms/1000; +if ms < EEG.xmin || ms > EEG.xmax + error('time out of range'); +end +outf = 1+round((EEG.pnts-1)*(ms-EEG.xmin)/(EEG.xmax-EEG.xmin)); +% else +% [tmp outf] = min(abs(EEG.times-ms)); diff --git a/functions/miscfunc/eeg_time2prev.m b/functions/miscfunc/eeg_time2prev.m index 65f831892..4c1f07d8b 100644 --- a/functions/miscfunc/eeg_time2prev.m +++ b/functions/miscfunc/eeg_time2prev.m @@ -1,9 +1,9 @@ -% eeg_time2prev() - returns a vector giving, for each event of specified ("target") type(s), +% EEG_TIME2PREV - returns a vector giving, for each event of specified ("target") type(s), % the delay (in ms) since the preceding event (if any) of specified % ("previous") type(s). Requires the EEG.urevent structure, plus -% EEG.event().urevent pointers to it. +% EEG.EVENT.urevent pointers to it. % -% NOW SUPERCEDED BY eeg_context() +% NOW SUPERSEDED BY EEG_CONTEXT % Usage: % >> [delays,targets,urtargs,urprevs] = eeg_time2prev(EEG,{target},{previous}); % Inputs: @@ -28,6 +28,33 @@ %% % Scott Makeig & Arnaud Delorme, SCCN/INC/UCSD, August 28, 2003 +% Copyright (C) Scott Makeig & Arnaud Delorme, SCCN/INC/UCSD, August 28, 2003 +% +% 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 [delays,targets,urtargets,urprevs] = eeg_time2prev(EEG,target,previous); verbose = 1; % FLAG (1=on|0=off) @@ -72,9 +99,9 @@ %%%%%%%%%%%%%%%%%%%% Initialize output arrays %%%%%%%%%%%%%%%%%%%%%% % delays = zeros(1,nevents); % holds output times in ms -targets = zeros(1,nevents); % holds indxes of targets -urtargets = zeros(1,nevents); % holds indxes of targets -urprevs = zeros(1,nevents); % holds indxes of prevs +targets = zeros(1,nevents); % holds indexes of targets +urtargets = zeros(1,nevents); % holds indexes of targets +urprevs = zeros(1,nevents); % holds indexes of prevs targetcount = 0; % index of current target % Below: diff --git a/functions/miscfunc/eegdraw.m b/functions/miscfunc/eegdraw.m index 54535260d..0bd14947a 100644 --- a/functions/miscfunc/eegdraw.m +++ b/functions/miscfunc/eegdraw.m @@ -1,22 +1,33 @@ -% eegdraw() - subroutine used by eegplotold() to plot data. +% EEGDRAW - subroutine used by EEGPLOTOLD to plot data. % % Author: Colin Humphries, CNL, Salk Institute, La Jolla, 7/96 -% Copyright (C) Colin Humphries, CNL, Salk Institute 7/96 from eegplot() +% Copyright (C) Colin Humphries, CNL, Salk Institute 7/96 from EEGPLOT % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 11-07-97 fix incorrect start times -Scott Makeig % 01-25-02 reformated help & license -ad diff --git a/functions/miscfunc/eegdrawg.m b/functions/miscfunc/eegdrawg.m index 5c3289874..504bdf0b5 100644 --- a/functions/miscfunc/eegdrawg.m +++ b/functions/miscfunc/eegdrawg.m @@ -1,24 +1,35 @@ -% eegdrawg() - subroutine used by eegplotgold() to plot data. +% EEGDRAWG - subroutine used by EEGPLOTGOLD to plot data. % % Author: Colin Humphries, CNL, Salk Institute, La Jolla, 7/96 -% Copyright (C) Colin Humphries, CNL, Salk Institute 7/96 from eegplot() +% Copyright (C) Colin Humphries, CNL, Salk Institute 7/96 from EEGPLOT % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -% 4-4-97 shortened name to eegdrawq() -sm +% 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. + +% 4-4-97 shortened name to EEGDRAWQ -sm % 4-7-97 allowed data names other than 'data' -ch % 01-25-02 reformated help & license -ad diff --git a/functions/miscfunc/eegmovie.m b/functions/miscfunc/eegmovie.m index 4720fae9a..f19df81d9 100644 --- a/functions/miscfunc/eegmovie.m +++ b/functions/miscfunc/eegmovie.m @@ -1,6 +1,6 @@ -% eegmovie() - Compile and view a Matlab movie. -% Uses scripts eegplotold() and topoplot(). -% Use seemovie() to display the movie. +% EEGMOVIE - Compile and view a Matlab movie. +% Uses scripts EEGPLOTOLD and TOPOPLOT. +% Use SEEMOVIE to display the movie. % Usage: % >> [Movie,Colormap] = eegmovie(data,srate,elec_locs, 'key', val, ...); % @@ -44,23 +44,36 @@ % % Author: Arnaud Delorme, Colin Humphries & Scott Makeig, CNL, Salk Institute, La Jolla, 3/97 % -% See also: seemovie(), eegplotold(), topoplot() +% Example of usage for 3D movie: see https://github.com/amisepa/eegmovie_topo3d +% +% See also: SEEMOVIE, EEGPLOTOLD, TOPOPLOT % Copyright (C) 6/4/97 Colin Humphries & Scott Makeig, CNL / Salk Institute / La Jolla CA % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% 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. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% 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. % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 6/6/97 added movieframes arg -sm % 6/12/97 removed old 'startframes' var., fixed vertical line frame selection -sm @@ -100,7 +113,7 @@ if nargin>=4, options = { options{:} 'title' varargin{1} }; end else options = varargin; -end; +end opt = finputcheck(options, { 'startsec' 'real' {} 0; 'minmax' 'real' {} 0; @@ -114,7 +127,7 @@ 'time' 'string' { 'on' 'off' } 'off'; 'topoplotopt' 'cell' {} {}; 'headplotopt' 'cell' {} {} }, 'eegmovie'); -if isstr(opt), error(opt); end; +if ischar(opt), error(opt); end if opt.minmax ==0, datamin = min(min(data)); datamax = max(max(data)); @@ -135,13 +148,13 @@ if srate ==0, srate = DEFAULT_SRATE; end -if strcmpi(opt.time, 'on'), opt.framenum = 'off'; end; +if strcmpi(opt.time, 'on'), opt.framenum = 'off'; end mframes = length(opt.movieframes); fprintf('Making a movie of %d frames\n',mframes) Movie = moviein(mframes,gcf); -%%%%%%%%%%%%%%%%%%%%% eegplot() of data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%% EEGPLOT of data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if strcmpi(opt.timecourse, 'on') axeegplot = axes('Units','Normalized','Position',[.75 .05 .2 .9]); @@ -152,12 +165,12 @@ adddots = '...'; for iChan = 1:length(eloc_locs) fprintf(fid, '0 0 0 %s\n', [ eloc_locs(iChan).labels adddots(length(eloc_locs(iChan).labels):end) ]); - end; + end fclose(fid); eegplotold('noui',-data,srate,0,'tmp_file.loc',opt.startsec,'r'); else eegplotold('noui',-data,srate,0,eloc_locs,opt.startsec,'r'); - end; + end % set(axeegplot,'XTick',[]) %%CJH % plot negative up @@ -170,8 +183,8 @@ frameind = (opt.vert(ind)-opt.startsec)*srate+1; line([frameind frameind],limits,'color','k'); % draw vertical line at map timepoint set(axeegplot,'Xtick',frameind,'XtickLabel',num2str(opt.vert(ind),'%4.3f')); - end; -end; + end +end %%%%%%%%%%%%%%%%%%%%% topoplot/headplot axis %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -190,7 +203,7 @@ if isequal(opt.camerapath, 0) opt.camerapath = [-127 0 30 0]; fprintf('Using default view [-127 0 30 0].'); - end; + end if size(opt.camerapath,2)~=4 error('Camerapath parameter must have exact 4 columns'); end @@ -206,7 +219,7 @@ elevation = opt.camerapath(1,3); el_step = opt.camerapath(1,4); -end; +end %%%%%%%%%%%%%%%%%%%%%%%%% "Roll'em!" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -219,7 +232,7 @@ x1 = opt.startsec+(indFrame-1)/srate; l1 = line([indFrame indFrame],limits,'color','b'); % draw vertical line at map timepoint set(axeegplot,'Xtick',indFrame,'XtickLabel',num2str(x1,'%4.3f')); - end; + end % plot headplot or topoplot axes(axtopoplot) @@ -260,7 +273,7 @@ 'PlotBoxAspectRatioMode','manual',... 'DataAspectRatioMode','manual'); % keep camera distance constant - end; + end % show frame number if strcmpi(opt.framenum, 'on') @@ -269,17 +282,17 @@ elseif strcmpi(opt.time, 'on') txt = sprintf('%3.3f s', opt.startsec+(indFrame-1)/srate); text(-0.5,-0.5,txt,'FontSize',14); - end; + end Movie(:,f) = getframe(gcf); drawnow if strcmpi(opt.timecourse, 'on') delete(l1) - end; + end % print advancement fprintf('.',f); - if rem(indFrame,10) == 0, fprintf('%d',f); end; + if rem(indFrame,10) == 0, fprintf('%d',f); end if rem(indFrame,50) == 0, fprintf('\n'); end end fprintf('\nDone\n'); diff --git a/functions/miscfunc/eegplotgold.m b/functions/miscfunc/eegplotgold.m index dbcb7fed1..eede3fdf9 100644 --- a/functions/miscfunc/eegplotgold.m +++ b/functions/miscfunc/eegplotgold.m @@ -1,4 +1,4 @@ -% eegplotgold() - display EEG data in a clinical format +% EEGPLOTGOLD - display EEG data in a clinical format % % Usage: % >> eegplotgold('dataname', samplerate, 'chanfile', 'title', yscaling, range) @@ -6,13 +6,13 @@ % Inputs: % 'dataname' - quoted name of a desktop global variable (see Ex. below) % samplerate - EEG sampling rate in Hz (0 -> default 256 Hz) -% 'chanfile' - file of channel info in topoplot() style +% 'chanfile' - file of channel info in TOPOPLOT style % (0 -> channel numbers) -% 'title' - plot title string (0 -> 'eegplotgold()') +% 'title' - plot title string (0 -> 'EEGPLOTGOLD') % yscaling - initial y scaling factor (0 - default is 300) % range - how many seconds to display in window (0 -> 10) % -% Note: this version of eegplotgold() reguires that your data matrix +% Note: this version of EEGPLOTGOLD requires that your data matrix % be defined as a global variable before running this routine. % % Example: >> global dataname @@ -20,25 +20,36 @@ % % Author: Colin Humphries, CNL, Salk Institute, La Jolla, 3/97 % -% See also: eegplot(), eegplotold(), eegplotsold() +% See also: EEGPLOT, EEGPLOTOLD, EEGPLOTSOLD -% Copyright (C) Colin Humphries, CNL, Salk Institute 3/97 from eegplotold() +% Copyright (C) Colin Humphries, CNL, Salk Institute 3/97 from EEGPLOTOLD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -% 4-4-97 shortened name to eegplotgold() -sm +% 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. + +% 4-4-97 shortened name to EEGPLOTGOLD -sm % 5-20-97 added read of icadefs.m for MAXEEGPLOTCHANS -sm % 8-10-97 Clarified chanfile type -sm % 01-25-02 reformated help & license, added links -ad @@ -100,7 +111,7 @@ end if samplerate == 0, samplerate = DEFAULT_SAMPLERATE; -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Define internal variables @@ -124,7 +135,7 @@ channamefile = 0; else fprintf('Chan info file %s opened\n',channamefile); - end; + end icadefs; % read MAXEEGPLOTCHANS from icadefs.m if errorcode==0, @@ -135,18 +146,18 @@ for j=1:c if channames(i,j)=='.', channames(i,j)=' '; - end; - end; - end; + end + end + end % fprintf('%d channel names read from file.\n',r); if (r>chans) fprintf('Using first %d names.\n',chans); channames = channames(1:chans,:); - end; + end if (r> eegplotold(data,srate,spacing,eloc_file,windowlength,title) @@ -17,23 +17,34 @@ % % Author: Colin Humphries, CNL, Salk Institute, La Jolla, 5/98 % -% See also: eegplot(), eegplotgold(), eegplotsold() +% See also: EEGPLOT, EEGPLOTGOLD, EEGPLOTSOLD -% Copyright (C) Colin Humphries, CNL, Salk Institute 3/97 from eegplotold() +% Copyright (C) Colin Humphries, CNL, Salk Institute 3/97 from EEGPLOTOLD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % Runs under Matlab 5.0+ (not supported for Matlab 4) % @@ -82,7 +93,7 @@ % Setup inputs % %%%%%%%%%%%%%%%%%%%%%%%% -if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols +if ~ischar(data) % If NOT a 'noui' call or a callback from uicontrols if nargin == 7 % undocumented feature - allows position to be specd. posn = p6; @@ -151,7 +162,7 @@ YLabels = flipud(str2mat(YLabels,' ')); elseif length(eloc_file) == chans YLabels = num2str(eloc_file'); - elseif length(eloc_file) == 1 & eloc_file(1) == 0 + elseif length(eloc_file) == 1 && eloc_file(1) == 0 YLabels = num2str((1:chans)'); % Use numbers else YLabels = []; % no labels used @@ -203,7 +214,7 @@ 'XColor',DEFAULT_AXIS_COLOR,... 'YColor',DEFAULT_AXIS_COLOR); - if isstr(titleval) % plot title + if ischar(titleval) % plot title title(titleval) elseif titleval == 2 title(inputname(1)) @@ -532,7 +543,7 @@ spacing = str2num(get(ESpacing,'string')); % current spacing winlength = get(figh,'UserData'); - if isempty(spacing) | isempty(time) + if isempty(spacing) || isempty(time) return % return if valid numbers are not in the edit boxes end @@ -758,7 +769,7 @@ timestring = ['OBJ2 = findobj(''tag'',''electedit'');',... '[LAB1,LAB2] = uigetfile(''*'',''Electrode File'');',... - 'if (isstr(LAB1) & isstr(LAB2));',... + 'if (ischar(LAB1) & ischar(LAB2));',... 'set(OBJ2,''string'',[LAB2,LAB1]);',... 'end;',... 'clear OBJ2 LAB1 LAB2;']; @@ -956,7 +967,7 @@ end if spacing == 0 spacing = 1; - end; + end if Fs == 0 Fs = DEFAULT_SAMPLE_RATE; end diff --git a/functions/miscfunc/eegplotsold.m b/functions/miscfunc/eegplotsold.m index 9c0044ced..457370472 100644 --- a/functions/miscfunc/eegplotsold.m +++ b/functions/miscfunc/eegplotsold.m @@ -1,4 +1,4 @@ -% eegplotsold() - display data in a clinical format without scrolling +% EEGPLOTSOLD - display data in a clinical format without scrolling % % Usage: % >> eegplotsold(data, srate, 'chanfile', 'title', ... @@ -7,8 +7,8 @@ % Inputs: % data - data matrix (chans,frames) % srate - EEG sampling rate in Hz (0 -> 256 Hz) -% 'chanfile' - file of channel info, topoplot() style, (0 -> chan nos) -% 'title' - plot title string {0 -> 'eegplotsold()'} +% 'chanfile' - file of channel info, TOPOPLOT style, (0 -> chan nos) +% 'title' - plot title string {0 -> 'EEGPLOTSOLD'} % yscaling - initial y scaling factor (0 -> 300) % epoch - how many seconds to display in window (0 -> 10 sec) % linecolor - color of eeg (0 -> 'y') @@ -17,30 +17,41 @@ % % Author: Colin Humphries, CNL, Salk Institute, La Jolla, 3/97 % -% See also: eegplot(), eegplotold(), eegplotgold() +% See also: EEGPLOT, EEGPLOTOLD, EEGPLOTGOLD -% Copyright (C) Colin Humphries, CNL, Salk Institute 3/97 from eegplotold() +% Copyright (C) Colin Humphries, CNL, Salk Institute 3/97 from EEGPLOTOLD % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 05-01-97 added xstart argument -sm % 05-20-97 added read of icadefs.m % 06-12-97 EPOCH -> epoch line 71 below -sm % 8-10-97 Clarified chanfile type -sm -% 12-08-97 Added isstr(titleval) test -sm -% 02-09-98 legnth(data)->size(data,2) -sm +% 12-08-97 Added ischar(titleval) test -sm +% 02-09-98 length(data)->size(data,2) -sm % 01-25-02 reformated help & license, added links -ad %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -105,7 +116,7 @@ if nargin < 4 titleval = DEFAULT_TITLE; end -if ~isstr(titleval) +if ~ischar(titleval) if titleval == 0 titleval = DEFAULT_TITLE; else @@ -121,7 +132,7 @@ end if srate == 0, srate = DEFAULT_SRATE; -end; +end if PLOT_TIME == 0 PLOT_TIME = ceil(frames/srate); if PLOT_TIME > DEFAULT_EPOCH @@ -147,7 +158,7 @@ channamefile = 0; else % fprintf('Chan info file %s opened\n',channamefile); - end; + end if errorcode==0, channames = fscanf(chid,'%d %f %f %s',[7 MAXEEGPLOTCHANS]); channames = channames'; @@ -157,18 +168,18 @@ for j=1:c if channames(i,j)=='.', channames(i,j)=' '; % convert dots to spaces - end; - end; - end; + end + end + end % fprintf('%d channel names read from file.\n',r); if (r>chans) fprintf('Using first %d names.\n',chans); channames = channames(1:chans,:); - end; + end if (r 0 +if xstart<0 && xstart+PLOT_TIME > 0 linetime = round(-xstart/srate); line ([linetime linetime],[1e10,-1e10]); end diff --git a/functions/miscfunc/envproj.m b/functions/miscfunc/envproj.m index 8c920794f..05054244e 100644 --- a/functions/miscfunc/envproj.m +++ b/functions/miscfunc/envproj.m @@ -1,12 +1,12 @@ -% envproj() - plot envelopes of projections of selected ICA component +% ENVPROJ - plot envelopes of projections of selected ICA component % projections against envelope of the original data % % Usage: >> [envdata] = envproj(data,weights,compnums); % >> [envdata] = envproj(data,weights,compnums, ... % title,limits,chanlist,compnames,colors); % Inputs: -% data = runica() input data (chans,frames) <- best one epoch only! -% weights = unmixing weight matrix (runica() weights*sphere) +% data = RUNICA input data (chans,frames) <- best one epoch only! +% weights = unmixing weight matrix (RUNICA weights*sphere) % compnums = list of component numbers to project and plot % % Optional inputs: @@ -24,27 +24,38 @@ % % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 1/1997 % -% See also: envtopo() +% See also: ENVTOPO % Copyright (C) 01-23-97 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. -% 03-19-97 use datamean instead of frames/baseframes, diag(cov()) for var() -sm -% 04-03-97 changed name to envproj() -sm -% 05-20-97 used sum-of-squares for var instead of diag() to allow long data +% 03-19-97 use datamean instead of frames/baseframes, diag(COV) for VAR -sm +% 04-03-97 changed name to ENVPROJ -sm +% 05-20-97 used sum-of-squares for var instead of DIAG to allow long data % read MAXPLOTDATACHANS from icadefs.m -sm % 06-07-97 changed order of args to conform to runica -sm % 06-18-97 read MAXENVPLOTCHANS instead of MAXPLOTDATACHANS -sm @@ -66,7 +77,7 @@ % 06-05-98 made NEG_UP optional -sm % 02-22-99 added FILL mode default when numcomps==1 -sm % 03-14-99 made envelope finding code more efficient -sm -% 12-19-00 updated icaproj() args -sm +% 12-19-00 updated ICAPROJ args -sm % 01-25-02 reformated help & license, added links -ad function [envdata] = envproj(data,weights,compnums,titl,limits,chanlist,compnames,colors) @@ -119,20 +130,20 @@ % if chanlist == 0, chanlist = [1:chans]; -end; +end if compnums == 0, compnums = [1:wr]; -end; +end if size(compnums,1)>1, % handle column of compnums ! compnums = compnums'; -end; +end numcomps = length(compnums); if numcomps > MAXENVPLOTCHANS, fprintf(... 'envproj(): cannot plot more than %d channels of data at once.\n',... MAXENVPLOTCHANS); return -end; +end if max(compnums)>wr fprintf('\nenvproj(): Component index %d out of bounds (1:%d).\n',... @@ -146,7 +157,7 @@ return end -if FILL>0 & numcomps == 1 +if FILL>0 && numcomps == 1 FILL = 1; else FILL = 0; @@ -163,33 +174,33 @@ fprintf( ... 'envproj(): limits should be 0 or an array [xmin xmax ymin ymax].\n'); return - end; - if limits(1,1) == 0 & limits(1,2) ==0, + end + if limits(1,1) == 0 && limits(1,2) ==0, xmin=0; xmax=0; else xmin = limits(1,1); xmax = limits(1,2); - end; - if limits(1,3) == 0 & limits(1,4) ==0, + end + if limits(1,3) == 0 && limits(1,4) ==0, ymin=0; ymax=0; else ymin = limits(1,3); ymax = limits(1,4); - end; - end; + end + end - if xmax == 0 & xmin == 0, + if xmax == 0 && xmin == 0, x = (0:1:frames-1); xmin = 0; xmax = frames-1; else dx = (xmax-xmin)/(frames-1); x=xmin*ones(1,frames)+dx*(0:frames-1); % construct x-values - end; + end - if ymax == 0 & ymin == 0, + if ymax == 0 && ymin == 0, ymax=max(max(data(chanlist,:))); ymin=min(min(data(chanlist,:))); end @@ -197,7 +208,7 @@ % %%%%%%%%%%%%%%%%%%%% Read the color names %%%%%%%%%%%%%%%%%%%%%%%%%%%% % - if ~isstr(colors) + if ~ischar(colors) fprintf('envproj(): color file name must be a string.\n'); return end @@ -213,10 +224,10 @@ for j=1:c if colors(i,j)=='.', colors(i,j)=' '; - end; - end; - end; - end; + end + end + end + end [rr cc] = size(colors); % @@ -241,12 +252,12 @@ % append envelope of projected data sets onto envdata % Note: size(envdata) = [length(chanlist) frames*(numcomps+1)] n = n+1; -end; +end fprintf('\n'); % %%%%%%%%%%%%%%%%%%%%%%%% Make the plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -if ~isstr(titl) +if ~ischar(titl) if titl==0, titl = ' '; else @@ -310,7 +321,7 @@ l=ylabel('Potential (uV)'); % yaxis label set(l,'FontSize',14); -if xmax > 0 & xmin < 0 +if xmax > 0 && xmin < 0 plot([0 0],[ymin ymax],'k','linewidth',1.5); % plot vertical line at time 0 end diff --git a/functions/miscfunc/erpregout.m b/functions/miscfunc/erpregout.m index 4a64b7c24..3dc4d3370 100755 --- a/functions/miscfunc/erpregout.m +++ b/functions/miscfunc/erpregout.m @@ -1,87 +1,98 @@ -% erpregout() - regress out the ERP from the data -% -% Usage: -% newdata = erpregout(data); -% [newdata erp factors] = erpregout(data, tlim, reglim); -% -% Inputs: -% data - [float] 2-D data (times x trials) or 3-D data -% (channels x times x trials). -% -% Optional inputs: -% tlim - [min max] time limits in ms. -% reglim - [min max] regression time window in ms (by default -% the whole time period is used -% Outputs: -% newdata - data with ERP regressed out -% erp - data ERP -% factors - factors used for regressing out the ERP (size is the same -% as the number of trials or (channels x trials) -% -% Note: it is better to regress out the ERP about 4 times (launch the -% function 4 times in a row) to really be able to regress out the -% ERP and have a residual ERP close to 0. -% -% Author: Arnaud Delorme, Salk, SCCN, UCSD, CA, April 29, 2004 - -%123456789012345678901234567890123456789012345678901234567890123456789012 - -% Copyright (C) 2004 Arnaud Delorme -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -function [data, erp, factors] = erpregout(data, tlim, reglim); - - if nargin < 1 - help erpregout; - return; - end; - if nargin < 2 - tlim = [0 1]; - end; - if nargin < 3 - reglim = tlim; - end; - if ndims(data) == 2 - data = reshape(data, 1, size(data,1), size(data,2)); - redim = 1; - else - redim = 0; - end; - - % find closest points - % ------------------- - timevect = linspace(tlim(1), tlim(2), size(data,2)); - [tmp begpoint] = min( abs(timevect-reglim(1)) ); - [tmp endpoint] = min( abs(timevect-reglim(2)) ); - erp = mean(data, 3); - - % regressing out erp in channels and trials - % ----------------------------------------- - for chan = 1:size(data,1) - fprintf('Channel %d (trials out of %d):', chan, size(data,3)); - for trial = 1:size(data,3) - if ~mod(trial, 10) , fprintf('%d ', trial); end; - if ~mod(trial, 200), fprintf('\n', trial); end; - [factors(chan, trial) tmpf exitflag] = fminbnd('erpregoutfunc', 0, 10, [], ... - data(chan, begpoint:endpoint, trial), erp(chan, begpoint:endpoint)); - data(chan,:,trial) = data(chan,:,trial) - factors(chan, trial)*erp(chan, :); - end; - fprintf('\n'); - end; - - if redim - data = squeeze(data); - end; \ No newline at end of file +% ERPREGOUT - regress out the ERP from the data +% +% Usage: +% newdata = erpregout(data); +% [newdata erp factors] = erpregout(data, tlim, reglim); +% +% Inputs: +% data - [float] 2-D data (times x trials) or 3-D data +% (channels x times x trials). +% +% Optional inputs: +% tlim - [min max] time limits in ms. +% reglim - [min max] regression time window in ms (by default +% the whole time period is used +% Outputs: +% newdata - data with ERP regressed out +% erp - data ERP +% factors - factors used for regressing out the ERP (size is the same +% as the number of trials or (channels x trials) +% +% Note: it is better to regress out the ERP about 4 times (launch the +% function 4 times in a row) to really be able to regress out the +% ERP and have a residual ERP close to 0. +% +% Author: Arnaud Delorme, Salk, SCCN, UCSD, CA, April 29, 2004 + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2004 Arnaud Delorme +% +% 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 [data, erp, factors] = erpregout(data, tlim, reglim); + + if nargin < 1 + help erpregout; + return; + end + if nargin < 2 + tlim = [0 1]; + end + if nargin < 3 + reglim = tlim; + end + if ndims(data) == 2 + data = reshape(data, 1, size(data,1), size(data,2)); + redim = 1; + else + redim = 0; + end + + % find closest points + % ------------------- + timevect = linspace(tlim(1), tlim(2), size(data,2)); + [tmp begpoint] = min( abs(timevect-reglim(1)) ); + [tmp endpoint] = min( abs(timevect-reglim(2)) ); + erp = mean(data, 3); + + % regressing out erp in channels and trials + % ----------------------------------------- + for chan = 1:size(data,1) + fprintf('Channel %d (trials out of %d):', chan, size(data,3)); + for trial = 1:size(data,3) + if ~mod(trial, 10) , fprintf('%d ', trial); end + if ~mod(trial, 200), fprintf('\n', trial); end + [factors(chan, trial) tmpf exitflag] = fminbnd('erpregoutfunc', 0, 10, [], ... + data(chan, begpoint:endpoint, trial), erp(chan, begpoint:endpoint)); + data(chan,:,trial) = data(chan,:,trial) - factors(chan, trial)*erp(chan, :); + end + fprintf('\n'); + end + + if redim + data = squeeze(data); + end diff --git a/functions/miscfunc/erpregoutfunc.m b/functions/miscfunc/erpregoutfunc.m index b9e7b5003..243b86a9d 100755 --- a/functions/miscfunc/erpregoutfunc.m +++ b/functions/miscfunc/erpregoutfunc.m @@ -1,38 +1,49 @@ -% erpregoutfunc() - sub function of erpregout() used to regress -% out the ERP from the data -% -% Usage: -% totdiff = erpregout(fact, data, erp); -% -% Inputs: -% fact - factor -% data - [float] 1-D data (time points). -% erp - [float] 1-D data (time points). -% -% Outputs: -% totdif - residual difference -% -% Author: Arnaud Delorme, Salk, SCCN, UCSD, CA, April 29, 2004 - -%123456789012345678901234567890123456789012345678901234567890123456789012 - -% Copyright (C) 2004 Arnaud Delorme -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -function totdiff = erpregoutfunc(fact, data, erp); - - totdiff = mean(abs(data - fact*erp)); - \ No newline at end of file +% ERPREGOUTFUNC - sub function of ERPREGOUT used to regress +% out the ERP from the data +% +% Usage: +% totdiff = erpregout(fact, data, erp); +% +% Inputs: +% fact - factor +% data - [float] 1-D data (time points). +% erp - [float] 1-D data (time points). +% +% Outputs: +% totdif - residual difference +% +% Author: Arnaud Delorme, Salk, SCCN, UCSD, CA, April 29, 2004 + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2004 Arnaud Delorme +% +% 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 totdiff = erpregoutfunc(fact, data, erp); + + totdiff = mean(abs(data - fact*erp)); + diff --git a/functions/miscfunc/eucl.m b/functions/miscfunc/eucl.m index 748a8d40b..ca011d46f 100644 --- a/functions/miscfunc/eucl.m +++ b/functions/miscfunc/eucl.m @@ -1,3 +1,4 @@ +function dists = eucl(crds1,crds2) % EUCL: Calculates the euclidean distances among a set of points, or between a % reference point and a set of points, or among all possible pairs of two % sets of points, in P dimensions. Returns a single distance for two points. @@ -31,15 +32,14 @@ % 6/12/98 - allow for P=1. % 11/11/03 - initialize dists to NaN for error return. -function dists = eucl(crds1,crds2) - if nargin == 0, help eucl; return; end; + if nargin == 0, help eucl; return; end dists = NaN; if (nargin < 2) % If only crds1 provided, [N,P] = size(crds1); if (N<2) error(' EUCL: need at least two points'); - end; + end crds1 = crds1'; % Transpose crds dists = zeros(N,N); % Calculate pairwise distances @@ -50,13 +50,13 @@ d = sqrt(sum((c1-crds1(:,(i+1:N))).^2)); else d = abs(c1-crds1(:,(i+1:N))); - end; + end dists(i,(i+1:N)) = d; dists((i+1:N),i) = d'; - end; + end if (N==2) % Single distance for two points dists = dists(1,2); - end; + end else % If crds1 & crds2 provided, [N1,P1] = size(crds1); @@ -65,12 +65,12 @@ error(' EUCL: sets of coordinates must be of same dimension'); else P = P1; - end; + end crds1 = crds1'; % Transpose crds crds2 = crds2'; - if (N1>1 & N2>1) % If two matrices provided, + if (N1>1 && N2>1) % If two matrices provided, dists = zeros(N1,N2); % Calc all pairwise distances between them for i = 1:N1 c1 = crds1(:,i) * ones(1,N2); @@ -78,33 +78,33 @@ d = sqrt(sum((c1-crds2).^2)); else d = abs(c1-crds2); - end; + end dists(i,:) = d; - end; - end; + end + end - if (N1==1 & N2==1) % If two vectors provided, + if (N1==1 && N2==1) % If two vectors provided, dists = sqrt(sum((crds1-crds2).^2)); % Calc scalar - end; + end - if (N1>1 & N2==1) % If matrix & reference point provided, + if (N1>1 && N2==1) % If matrix && reference point provided, crds1 = crds1 - (ones(N1,1)*crds2')'; % Center points on reference point if (P>1) % Calc euclidean distances in P-space dists = sqrt(sum(crds1.^2))'; else dists = abs(crds1)'; - end; + end end; % Return column vector - if (N1==1 & N2>1) % If reference point & matrix provided, + if (N1==1 && N2>1) % If reference point && matrix provided, crds2 = crds2 - (ones(N2,1)*crds1')'; % Center points on reference point if (P>1) % Calc euclidean distances in P-space dists = sqrt(sum(crds2.^2)); else dists = abs(crds2); - end; + end end; % Return row vector - end; + end return; diff --git a/functions/miscfunc/fastregress.m b/functions/miscfunc/fastregress.m index 71090e113..290daf313 100644 --- a/functions/miscfunc/fastregress.m +++ b/functions/miscfunc/fastregress.m @@ -1,26 +1,62 @@ % fastregress - perform fast regression and return p-value % % Usage: -% [ypred, alpha, rsq, B] = myregress(x, y, plotflag); +% [ypred, alpha, rsq, slope, intercept] = fastregress(x, y); +% [ypred, alpha, rsq, slope, intercept] = fastregress(x, y, plotflag, plotleg); % % Inputs % y - y values % x - x values -% plotflag - [0|1] plot regression +% plotflag - [0|1] plot regression and legend. Default 0. +% plotleg - [0|1] plot legend. Default same as plotflag. % % Outputs % ypred - y prediction % alpha - significance level % R^2 - r square % slope - slope of the fit +% intercept - intercept of the fit % % Arnaud Delorme, 25 Feb 2003 -function [ypred, alpha, rsq, B] = fastregress(x, y, ploting); +% Copyright (C) Arnaud Delorme, 25 Feb 2003 +% +% 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 [ypred, alpha, rsq, B, intercept, h] = fastregress(x, y, plotflag, plotleg) if nargin < 1 help fastregress; return; - end; + end + if nargin < 3 + plotflag = false; + end + if nargin < 4 + plotleg = plotflag; + end % this part is useless but still works %B=polyfit(x, y, 1); % B is the slope @@ -41,12 +77,15 @@ ypred = x*B(2) + B(1); % B(1) contain the offset, B(2) the slope + intercept = B(1); B = B(2); - if nargin > 2 + if plotflag hold on; - [ynew tmp] = sort(ypred); - xnew = x(tmp); - plot(xnew, ynew, 'r'); + [ynew, tmp] = sort(ypred); + xnew = x(tmp); + h = plot(xnew, ynew, 'r'); + end + if plotleg legend(sprintf('R^2=%f', rsq), sprintf('p =%f', alpha)); - end; \ No newline at end of file + end diff --git a/functions/miscfunc/fieldtrip2eeglab.m b/functions/miscfunc/fieldtrip2eeglab.m index 77c1acb99..270cd25bf 100644 --- a/functions/miscfunc/fieldtrip2eeglab.m +++ b/functions/miscfunc/fieldtrip2eeglab.m @@ -1,52 +1,140 @@ -% load data file ('dataf') preprocessed with fieldtrip -% and show in eeglab viewer -% -% This function is provided as is. It only works for some specific type of -% data. This is a simple function to help the developer and by no mean -% an all purpose function. - -function [EEG] = fieldtrip2eeglab(dataf) - -[ALLEEG EEG CURRENTSET ALLCOM] = eeglab; - -if exist(dataf,'file') - load(dataf) -end - -% load chanlocs.mat -% EEG.chanlocs = chanlocs; -EEG.chanlocs = []; - -for i=1:size(data.trial,2) - EEG.data(:,:,i) = single(data.trial{i}); -end - -EEG.setname = dataf; %data.cfg.dataset; -EEG.filename = ''; -EEG.filepath = ''; -EEG.subject = ''; -EEG.group = ''; -EEG.condition = ''; -EEG.session = []; -EEG.comments = 'preprocessed with fieldtrip'; -EEG.nbchan = size(data.trial{1},1); -EEG.trials = size(data.trial,2); -EEG.pnts = size(data.trial{1},2); -EEG.srate = data.fsample; -EEG.xmin = data.time{1}(1); -EEG.xmax = data.time{1}(end); -EEG.times = data.time{1}; -EEG.ref = []; %'common'; -EEG.event = []; -EEG.epoch = []; -EEG.icawinv = []; -EEG.icasphere = []; -EEG.icaweights = []; -EEG.icaact = []; -EEG.saved = 'no'; - -[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG); -eeglab redraw -pop_eegplot( EEG, 1, 1, 1); - - \ No newline at end of file +% fieldtrip2eeglab - convert Fieldtrip structures to EEGLAB dataset +% +% EEG = fieldtrip2eeglab(header, rawdata, evt); +% EEG = fieldtrip2eeglab(data); +% +% Inputs: +% header - Fieldtrip data header +% rawdata - Fieldtrip raw data +% evt - Fieldtrip event structure (optional) +% data - Fieldtrip data out of ft_preprocessing. Note that this uses +% a legacy conversion method. It is better to use +% fieldtrip2eeglab(data.hdr, data.trial) to use the default +% FileIO API. +% +% Output: +% EEG - EEGLAB structure +% +% Author: Arnaud Delorme, UCSD + +% Copyright (C) Arnaud Delorme, UCSD 2018 +% +% 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 = fieldtrip2eeglab(header,data,evt) + +if nargin < 3 + evt = []; +end + +if nargin >= 2 + EEG = pop_fileio(header, data, evt); +else + fprintf(2, 'fieldtrip2eeglab: Use 2-input argument, header and data to use the fileio API to convert Fieldtrip data\n') + + if isfield(header, 'hdr') + % use the hdr field in the data + hdr = header.hdr; + if isfield(header, 'label') + hdr.label = header.label; + end + else + % create a minimal header + hdr.nChans = numel(header.label); + hdr.nSamplesPre = 0; % FIXME perhaps better to make it nan?; And what about nSamplesPst? + if iscell(header.trial) + hdr.nTrials = numel(header.trial); + hdr.nSamples = numel(header.time{1}); % variable length trials will be caught below + if isfield(header, 'fsample') + hdr.Fs = header.fsample; + else + hdr.Fs = 1./mean(diff(header.time{1})); + end + else + hdr.nTrials = size(header.trial,1); + hdr.nSamples = numel(header.time); + if isfield(header, 'fsample') + hdr.Fs = header.fsample; + else + hdr.Fs = 1./mean(diff(header.time)); + end + end + + end + + EEG = pop_fileio(hdr, header); + if iscell(EEG.data) && length(EEG.data) == 1 + EEG.data = EEG.data{1}; + EEG.times = header.time{1}; + elseif iscell(EEG.data) + len = cellfun(@(x)size(x,2), EEG.data); + unLen = unique(len); + if length(unLen) > 1 + if length(unLen) > 2 || diff(unLen) > 1 + error('Epochs of different length, conversion is not possible'); + else + fprintf(2, 'Epochs of different length, but small difference in sample\n'); + fprintf(2, 'Assuming outlier due to fractional sample limits and selecting the most common epoch length\n'); + e1 = sum(len == unLen(1)); + e2 = sum(len == unLen(2)); + if min(e1, e2) > 5 + error('Too many epochs to remove, check data'); + end + if e1 > e2 + fprintf(2, 'Truncating %d epochs\n', e2); + epochsToTruncate = find(len == unLen(2)); + truncateLen = unLen(1); + else + fprintf(2, 'Truncating %d epochs\n', e1); + epochsToTruncate = find(length == unLen(1)); + truncateLen = unLen(2); + end + for iEpoch = 1:length(epochsToTruncate) + EEG.data{epochsToTruncate(iEpoch)} = EEG.data{epochsToTruncate(iEpoch)}(:,1:end-1); + end + end + end + % EEG.data = [ EEG.data{:} ]; + EEG.data = cat(3, EEG.data{:}); + EEG.pnts = len(1); + else + % error('Unknown fieldtrip data format'); + % the trial field was a 3D matrix + EEG.data = permute(EEG.data, [2 3 1]); + + % overrule the previously created metadata + [EEG.nbchan, EEG.pnts, EEG.trials] = size(EEG.data); + end + if iscell(header.time) % assuming uniformity of trials + EEG.xmin = header.time{1}(1); + EEG.xmax = header.time{1}(end); + else + EEG.xmin = header.time(1); + EEG.xmax = header.time(end); + end + EEG.trials = size(EEG.data,3); + EEG = eeg_checkset(EEG); +end diff --git a/functions/miscfunc/fillcurves.m b/functions/miscfunc/fillcurves.m index c7fa2d07b..8a82a5ca9 100644 --- a/functions/miscfunc/fillcurves.m +++ b/functions/miscfunc/fillcurves.m @@ -1,4 +1,4 @@ -% fillcurves() - fill the space between 2 curves +% FILLCURVES - fill the space between 2 curves % % Usage: % h=fillcurves( Y1, Y2); @@ -13,40 +13,51 @@ % Copyright (C) Arnaud Delorme, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 h = fillcurves(X, Y1, Y2, color, transparent, legends) if nargin < 2 help fillcurves; return; - end; + end if nargin < 3 Y2 = Y1; Y1 = X; X = [1:length(Y1)]; - end; + end if nargin < 4 || isempty(color) color = { 'r' 'b' 'g' 'c' }; elseif ~iscell(color) color = { color }; - end; + end if nargin < 5 transparent = 0.5; - end; + end X1 = X(:)'; X2 = X(:)'; @@ -62,7 +73,7 @@ tmp2 = find(~Y2); Y1(tmp1) = []; X1(tmp1) = []; Y2(tmp2) = []; X2(tmp2) = []; - end; + end % multiple curve plot % ------------------- @@ -70,11 +81,11 @@ for index = 1:size(Y1,2) fillcurves(X, Y1(:,index)', Y2(:,index)', color{index}, transparent); hold on; - end; - yl = ylim; - xl = xlim; - line([xl(1) xl(1)]+(xl(2)-xl(1))/2000, yl, 'color', 'k'); - line(xl, [yl(1) yl(1)]+(yl(2)-yl(1))/2000, 'color', 'k'); + end +% yl = ylim; +% xl = xlim; +% line([xl(1) xl(1)]+(xl(2)-xl(1))/2000, yl, 'color', 'k'); +% line(xl, [yl(1) yl(1)]+(yl(2)-yl(1))/2000, 'color', 'k'); % write legend and add transparency to it % --------------------------------------- @@ -86,11 +97,11 @@ if isfield(fields, 'FaceAlpha'); numfaces = size(get(hh(index), 'Vertices'),1); set(hh(index), 'FaceVertexCData', repmat([1 1 1], [numfaces 1]), 'Cdatamapping', 'direct', 'facealpha', transparent, 'edgecolor', 'none'); - end; - end; - end; + end + end + end return; - end; + end % plot % ---- @@ -102,14 +113,14 @@ if transparent numfaces = size(get(h, 'Vertices'),1); set(h, 'FaceVertexCData', repmat([1 1 1], [numfaces 1]), 'Cdatamapping', 'direct', 'facealpha', transparent, 'edgecolor', 'none'); - end; + end % replot lines at boundaries % -------------------------- - parent = dbstack; - if length(parent) == 1 || ~strcmpi(parent(2).name, 'fillcurves') - yl = ylim; - xl = xlim; - line([xl(1) xl(1)]+(xl(2)-xl(1))/2000, yl, 'color', 'k'); - line(xl, [yl(1) yl(1)]+(yl(2)-yl(1))/2000, 'color', 'k'); - end; +% parent = dbstack; +% if length(parent) == 1 || ~strcmpi(parent(2).name, 'fillcurves') +% yl = ylim; +% xl = xlim; +% line([xl(1) xl(1)]+(xl(2)-xl(1))/2000, yl, 'color', 'k'); +% line(xl, [yl(1) yl(1)]+(yl(2)-yl(1))/2000, 'color', 'k'); +% end diff --git a/functions/miscfunc/findduplicatefunctions.m b/functions/miscfunc/findduplicatefunctions.m index 840fb65d2..f3de52e9b 100644 --- a/functions/miscfunc/findduplicatefunctions.m +++ b/functions/miscfunc/findduplicatefunctions.m @@ -1,8 +1,35 @@ -% find potential conflict between Matlab functions +% script to find potential conflict between Matlab functions in the current +% path % % A. Delorme, May 25th, 2012 -matlabRoot = fileparts(fileparts(fileparts(fileparts(which('ispc'))))); +% Copyright (C) A. Delorme, May 25th, 2012 +% +% 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. + folders = path; delim = find(folders == ':'); delim = [ 0 delim length(folders)+1 ]; @@ -12,7 +39,7 @@ folderContent = dir(currentFolder); - if isempty(findstr(matlabRoot, currentFolder)) + if ~contains( currentFolder, matlabroot) rmpath(currentFolder); folderContent = { folderContent.name }; @@ -23,15 +50,23 @@ if length(currentFile) > 2 && strcmpi(currentFile(end-1:end), '.m') if ~strcmpi(currentFile, 'Contents.m') - if ~isempty(which(currentFile)) + tmp = which(currentFile); + + if ~isempty(tmp) fullFileName1 = fullfile(currentFolder, currentFile); fullFileName2 = which(currentFile); + % cond1 = contains(fullFileName1, 'toolbox/matlab') || contains(fullFileName1, 'toolbox\matlab'); + cond1 = contains(fullFileName1, matlabroot); + if cond1 + sadffdas + end + % if ~cond1 fprintf('Potential conflict between %s and %s\n', fullFileName1, fullFileName2); - end; - end; - end; - end; + end + end + end + end addpath(currentFolder); - end; -end; \ No newline at end of file + end +end diff --git a/functions/miscfunc/formatsvnrevision.m b/functions/miscfunc/formatsvnrevision.m deleted file mode 100644 index 613e5c6d5..000000000 --- a/functions/miscfunc/formatsvnrevision.m +++ /dev/null @@ -1,44 +0,0 @@ -function formatsvnrevision(v1, v2) - -disp('Getting revision information...'); -system(sprintf('svn log --verbose -r%d:%d > tmprev.txt', v1, v2)); - -oldpwd = pwd; -newpwd = fileparts(which('eeglab.m')); -cd(newpwd); - -fid = fopen('tmprev.txt', 'r'); - -state = 1; -while ~feof(fid) - txt = fgetl(fid); - if length(txt) > 4 && strcmpi(txt(1:4), '----') - state = 1; - if feof(fid), return; end; - end; - if state == 1, - % get rev number - txt = fgetl(fid); - rev = strtok(txt); - revnum = rev(2:end); - - % get function name - txt = fgetl(fid); - txt = fgetl(fid); - [tmp file] = strtok(txt); - file = deblank(file); - [tmp file ext] = fileparts(file); - file = [ file ext ]; - state = 2; - end; - if isempty(txt) - state = 3; - end; - if state == 3 - revinfo = fgetl(fid); - revinfo = revinfo(1:end); - state = 1; - fprintf('** %s, %s (SVN %s - Arno)\n', file, revinfo, revnum); - end; -end; -cd(oldpwd); diff --git a/functions/miscfunc/gabor2d.m b/functions/miscfunc/gabor2d.m index 3436ea6f5..87027aad7 100644 --- a/functions/miscfunc/gabor2d.m +++ b/functions/miscfunc/gabor2d.m @@ -1,4 +1,4 @@ -% gabor2d() - generate a two-dimensional gabor matrice. +% GABOR2D - generate a two-dimensional gabor matrice. % % Usage: % >> [ matrix ] = gabor2d(rows, columns); @@ -22,26 +22,37 @@ % 0 and 90 being the phase offset of the real and imaginary parts % cut - percentage (0->1) of maximum value below which to remove values % from the matrix {default: 0} -% Ouput: +% Output: % matrix - output gabor matrix % % Author: Arnaud Delorme, CNL / Salk Institute, 2001 % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 mat = gabor2d( sizeX, sizeY, freq, angle, sigmaX, sigmaY, meanX, ... meanY, dephase, cut); @@ -49,31 +60,31 @@ if nargin < 2 help gabor2d return; -end; +end if nargin < 3 freq = 360/sizeX; -end; +end if nargin < 4 angle = 0; -end; +end if nargin < 5 sigmaX = sizeX/5; -end; +end if nargin < 6 sigmaY = sizeY/5; -end; +end if nargin < 7 meanX = (sizeX+1)/2; -end; +end if nargin < 8 meanY = (sizeY+1)/2; -end; +end if nargin < 9 dephase = 0; -end; +end if nargin < 10 cut = 0; -end; +end freq = freq/180*pi; X = linspace(1, sizeX, sizeX)'* ones(1,sizeY); @@ -87,10 +98,10 @@ /((sigmaX*sigmaY)^(0.5)*pi); if cut > 0 - maximun = max(max(mat))*cut; - I = find(mat < maximun); + maximum = max(max(mat))*cut; + I = find(mat < maximum); mat(I) = 0; -end; +end return; @@ -103,7 +114,7 @@ .*exp(-0.5*( ((X-meanX)/sigmaX).*((X-meanX)/sigmaX)... +((Y-meanY)/sigmaY).*((Y-meanY)/sigmaY)))... /((sigmaX*sigmaY)^(0.5)*pi); - end; -end; + end +end return; diff --git a/functions/miscfunc/gauss.m b/functions/miscfunc/gauss.m index 00d1e2637..cf826979f 100644 --- a/functions/miscfunc/gauss.m +++ b/functions/miscfunc/gauss.m @@ -1,4 +1,5 @@ -% gauss() - return a smooth Gaussian window +function outvec = gauss(frames,sds) +% GAUSS - return a smooth Gaussian window % % Usage: % >> outvector = gauss(frames,sds); @@ -8,14 +9,12 @@ % sds = number of +/-std. deviations = steepness % (~0+ -> flat; >>10 -> spike) -function outvec = gauss(frames,sds) - outvec = []; if nargin < 2 help gauss return end -if sds <=0 | frames < 1 +if sds <=0 || frames < 1 help gauss return end diff --git a/functions/miscfunc/gauss2d.m b/functions/miscfunc/gauss2d.m index 7ddcca1ae..c7677d3e0 100644 --- a/functions/miscfunc/gauss2d.m +++ b/functions/miscfunc/gauss2d.m @@ -1,4 +1,4 @@ -% gauss2d() - generate a 2-dimensional gaussian matrix +% GAUSS2D - generate a 2-dimensional gaussian matrix % % Usage: % >> [ gaussmatrix ] = gauss2d( rows, columns, ... @@ -16,48 +16,59 @@ % peakC - location of the peak in each column (default: columns/2) % mask - (0->1) portion of the matrix to mask with zeros (default: 0) % -% Ouput: +% Output: % gaussmatrix - 2-D gaussian matrix % % Author: Arnaud Delorme, CNL/Salk Institute, 2001 % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 mat = gauss2d( sizeX, sizeY, sigmaX, sigmaY, meanX, meanY, cut); if nargin < 2 help gauss2d return; -end; +end if nargin < 3 sigmaX = sizeX/5; -end; +end if nargin < 4 sigmaY = sizeY/5; -end; +end if nargin < 5 meanX = (sizeX+1)/2; -end; +end if nargin < 6 meanY = (sizeY+1)/2; -end; +end if nargin < 7 cut = 0; -end; +end X = linspace(1, sizeX, sizeX)'* ones(1,sizeY); Y = ones(1,sizeX)' * linspace(1, sizeY, sizeY); @@ -69,10 +80,10 @@ /((sigmaX*sigmaY)^(0.5)*pi); if cut > 0 - maximun = max(max(mat))*cut; - I = find(mat < maximun); + maximum = max(max(mat))*cut; + I = find(mat < maximum); mat(I) = 0; -end; +end return; diff --git a/functions/miscfunc/gauss3d.m b/functions/miscfunc/gauss3d.m index c29744985..b1866dfbc 100644 --- a/functions/miscfunc/gauss3d.m +++ b/functions/miscfunc/gauss3d.m @@ -1,4 +1,4 @@ -% gauss3d() - generate a 3-dimensional gaussian matrix +% GAUSS3D - generate a 3-dimensional gaussian matrix % % Usage: % >> [ gaussmatrix ] = gauss2d( nX, nY, nZ); @@ -22,54 +22,65 @@ % mask - (0->1) percentage of low values in the matrix to mask % with zeros (default: 0 or none) % -% Ouput: +% Output: % gaussmatrix - 3-D gaussian matrix % % Author: Arnaud Delorme, 2009 % Copyright (C) 2009 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 mat = gauss3d( sizeX, sizeY, sizeZ, sigmaX, sigmaY, sigmaZ, meanX, meanY, meanZ, cut); if nargin < 2 help gauss2d return; -end; +end if nargin < 4 sigmaX = sizeX/5; -end; +end if nargin < 5 sigmaY = sizeY/5; -end; +end if nargin < 6 sigmaZ = sizeZ/5; -end; +end if nargin < 7 meanX = (sizeX+1)/2; -end; +end if nargin < 8 meanY = (sizeY+1)/2; -end; +end if nargin < 9 meanZ = (sizeZ+1)/2; -end; +end if nargin < 10 cut = 0; -end; +end [X,Y,Z] = ndgrid(1:sizeX,1:sizeY,1:sizeZ); @@ -79,10 +90,10 @@ /((sigmaX*sigmaY*sigmaZ)^(0.5)*pi); if cut > 0 - maximun = max(mat(:))*cut; - I = find(mat < maximun); + maximum = max(mat(:))*cut; + I = find(mat < maximum); mat(I) = 0; -end; +end return; diff --git a/functions/miscfunc/getallmenus.m b/functions/miscfunc/getallmenus.m index d5f2331f0..bb8345feb 100644 --- a/functions/miscfunc/getallmenus.m +++ b/functions/miscfunc/getallmenus.m @@ -1,4 +1,4 @@ -% getallmenus() - get all submenus of a window or a menu and return +% GETALLMENUS - get all submenus of a window or a menu and return % a tree. % % Usage: @@ -15,19 +15,30 @@ % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [txt, nb, labels] = getallmenus( handler, level ) @@ -36,10 +47,10 @@ if nargin < 1 help getallmenus; return; - end; + end if nargin < 2 level = 0; - end; + end txt = ''; nb = 0; @@ -53,12 +64,12 @@ txt = [ txtmp txt ]; labels = { tmplab labels{:} }; nb = nb+nbtmp; - end; - end; + end + end try txt = [ get(handler, 'Label') 10 txt ]; nb = nb+1; - catch, end; + catch, end if isempty(labels) labels = { nb }; end; @@ -72,9 +83,9 @@ lines = find( txt == 10 ); for index = 1:length(lines)-1 tmptext = txt(lines(index)+1:lines(index+1)-1); - if maxlength < length( tmptext ), maxlength = length( tmptext ); end; + if maxlength < length( tmptext ), maxlength = length( tmptext ); end newtext(index, 1:length(tmptext)) = tmptext; - end; + end txt = char( newtext(1:index+1, 1:maxlength) ); end; return; diff --git a/functions/miscfunc/getallmenuseeglab.m b/functions/miscfunc/getallmenuseeglab.m index 2c82587e6..7ae099643 100644 --- a/functions/miscfunc/getallmenuseeglab.m +++ b/functions/miscfunc/getallmenuseeglab.m @@ -1,4 +1,4 @@ -% getallmenuseeglab() - get all submenus of a window or a menu and return +% GETALLMENUSEEGLAB - get all submenus of a window or a menu and return % a tree. The function will also look for callback. % % Usage: @@ -15,19 +15,30 @@ % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [txt, nb, labels] = getallmenuseeglab( handler, level ) @@ -36,10 +47,10 @@ if nargin < 1 help getallmenuseeglab; return; - end; + end if nargin < 2 level = 0; - end; + end txt = ''; nb = 0; @@ -53,8 +64,8 @@ txt = [ txtmp txt ]; labels = { tmplab labels{:} }; nb = nb+nbtmp; - end; - end; + end + end try lab = get(handler, 'Label'); cb = get(handler, 'Callback'); @@ -62,11 +73,11 @@ if ~isempty(cb) newtxt = [ lab ' - ' cb '']; else newtxt = [ lab ]; - end; + end txt = [ newtxt 10 txt ]; %txt = [ get(handler, 'Label') 10 txt ]; nb = nb+1; - catch, end; + catch, end if isempty(labels) labels = { nb }; end; @@ -76,7 +87,7 @@ fclose(fid); disp(' '); disp('Results saved in tmpfile.m'); - end; + end % transform into array of text % ---------------------------- @@ -87,9 +98,9 @@ lines = find( txt == 10 ); for index = 1:length(lines)-1 tmptext = txt(lines(index)+1:lines(index+1)-1); - if maxlength < length( tmptext ), maxlength = length( tmptext ); end; + if maxlength < length( tmptext ), maxlength = length( tmptext ); end newtext(index, 1:length(tmptext)) = tmptext; - end; + end txt = char( newtext(1:index+1, 1:maxlength) ); end; @@ -103,19 +114,19 @@ if ~isempty(indList), if strcmpi(cbin(indList(1):indList(1)+length('pop_stdwarn')-1), 'pop_stdwarn') indList = findstr(funcList{iList}, cbin(indList(1)+1:end))+indList(1); - end; + end break; - end; -end; + end +end if ~isempty(indList) indEndList = find( cbin(indList(1):end) == '(' ); if isempty(indEndList) || indEndList(1) > 25 indEndList = find( cbin(indList(1):end) == ';' ); if cbin(indList(1)+indEndList(1)-2) == ')' indEndList = indEndList-2; - end; - end; + end + end cbout = cbin(indList(1):indList(1)+indEndList(1)-2); else cbout = ''; -end; +end diff --git a/functions/miscfunc/getipsph.m b/functions/miscfunc/getipsph.m index 2a6b0812c..70d54d9d1 100644 --- a/functions/miscfunc/getipsph.m +++ b/functions/miscfunc/getipsph.m @@ -1,4 +1,4 @@ -% getipsph() - Compute "in place" (m by n) sphering or quasi-sphering matrix for an (n by t) +% GETIPSPH - Compute "in place" (m by n) sphering or quasi-sphering matrix for an (n by t) % input data matrix. Quasi-sphering reduces dimensionality of the data, while % maintaining approximately the "original" positions of the axes. That is, % quasi-sphering "rotates back" as much as possible into the original channel @@ -31,19 +31,30 @@ % Copyright (C) Jason Palmer, SCCN / INC / UCSD , La Jolla 2008 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 S = getipsph(x,m) diff --git a/functions/miscfunc/getmfilelist.m b/functions/miscfunc/getmfilelist.m new file mode 100644 index 000000000..588e8e2b1 --- /dev/null +++ b/functions/miscfunc/getmfilelist.m @@ -0,0 +1,56 @@ +% recursively get the list of Matlab file in +% a given directory +% +% A. Delorme, 2017 + +% Copyright (C) A. Delorme, 2017 +% +% 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 fileList = getmfilelist(folder) + +fileList = {}; +if nargin < 1 + folder = pwd; +end + +allFiles = dir(folder); + +for iFile = 1:length(allFiles) + + if ~isequal(allFiles(iFile).name, '..') && ~isequal(allFiles(iFile).name, '.') + + if exist(fullfile(folder, allFiles(iFile).name), 'dir') + fileList2 = getmfilelist(fullfile(folder, allFiles(iFile).name)); + fileList = [ fileList fileList2 ]; + elseif isequal(allFiles(iFile).name(end-1:end), '.m') + fileList{end+1} = fullfile(folder, allFiles(iFile).name); + end + + end +end + + diff --git a/functions/miscfunc/gradmap.m b/functions/miscfunc/gradmap.m index a291ee970..5bb1e25f7 100644 --- a/functions/miscfunc/gradmap.m +++ b/functions/miscfunc/gradmap.m @@ -1,4 +1,4 @@ -% gradmap() - compute the gradient of an EEG spatial distribution. +% GRADMAP - compute the gradient of an EEG spatial distribution. % % Usage: % >> [gradX, gradY ] = gradmap( map, filename, draw ) @@ -22,26 +22,37 @@ % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [gradx, grady] = gradmap( map, filename, draw ) if nargin < 2 help gradmap; return; -end; +end MAXCHANS = size(map,1); GRID_SCALE = 2*MAXCHANS+5; @@ -68,7 +79,7 @@ for i=1:MAXCHANS [useless_var horizidx(i)] = min(abs(y(i) - xi)); % find pointers to electrode [useless_var vertidx(i)] = min(abs(x(i) - yi)); % positions in Zi -end; +end draw = 1; @@ -91,8 +102,8 @@ quiver(imresize(FX, 0.5), imresize(FY, 0.5)); hold off else disp('Warning: cannot plot because imresize function is missing (image processing toolbox)'); - end; - end; + end + end end; return; diff --git a/functions/miscfunc/gradplot.m b/functions/miscfunc/gradplot.m index 70a7b17fa..bf77e9d22 100644 --- a/functions/miscfunc/gradplot.m +++ b/functions/miscfunc/gradplot.m @@ -1,4 +1,4 @@ -% gradplot() - Compute the gradient of EEG scalp map(s) on a square grid +% GRADPLOT - Compute the gradient of EEG scalp map(s) on a square grid % % Usage: % >> [gradX, gradY] = gradplot(maps,eloc_file,draw) @@ -12,27 +12,38 @@ % gradX - Gradients in X direction % gradY - Gradients in Y directions % -% Note: Use cart2pol() to convert to polar (amp, direction) coordinates). +% Note: Use CART2POL to convert to polar (amp, direction) coordinates). % % Authors: Marissa Westerfield & Arnaud Delorme, CNL/Salk Institute, La Jolla 3/10/01 % -% See also: topoplot(), lapplot() +% See also: TOPOPLOT, LAPPLOT % Copyright (C) 3/10/01 Marissa Westerfield & Arnaud Delorme, CNL/Salk Institute, La Jolla % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license, added links -ad @@ -41,7 +52,7 @@ if nargin < 2 help gradplot; return; -end; +end NCHANS = size(map,1); GRID_SCALE = 2*NCHANS+5; @@ -50,7 +61,7 @@ % -------------------------------- % Read the electrode location file % -------------------------------- -if isstr(locs_file) % a locs file +if ischar(locs_file) % a locs file [tmpeloc labels Th Rd ind] = readlocs(locs_file,'filetype', ... 'loc'); [x,y] = pol2cart(Th/180*pi,Rd); % See Bug 149 @@ -86,7 +97,7 @@ for c=1:NCHANS [useless_var horizidx(c)] = min(abs(y(c) - xi)); % find pointers to electrode [useless_var vertidx(c)] = min(abs(x(c) - yi)); % positions in Zi -end; +end % ------------------- % Compute gradient(s) @@ -160,7 +171,7 @@ axis off - end; -end; + end +end return; diff --git a/functions/miscfunc/headmovie.m b/functions/miscfunc/headmovie.m index 85d1e9e19..d57a36473 100644 --- a/functions/miscfunc/headmovie.m +++ b/functions/miscfunc/headmovie.m @@ -1,7 +1,7 @@ % ########## This function is deprecated. Use eegmovie instead. ########## % -% headmovie() - Record a Matlab movie of scalp data. -% Use seemovie() to display the movie. +% HEADMOVIE - Record a Matlab movie of scalp data. +% Use SEEMOVIE to display the movie. % % Usage: >> [Movie,Colormap] = headmovie(data,elec_loc,spline_file); % >> [Movie,Colormap,minc,maxc] = headmovie(data,elec_loc,spline_file,... @@ -9,7 +9,7 @@ % Inputs: % data = (chans,frames) EEG data set to plot % elec_loc = electrode locations file for eegplot {default 'chan.loc'} -% spline_file = headplot() produced spline 'filename' {default 'chan.spline'} +% spline_file = HEADPLOT produced spline 'filename' {default 'chan.spline'} % srate = sampling rate in Hz {default|0 -> 256 Hz} % title = 'plot title' {default|0 -> none} % camerapath = [az_start az_step el_start el_step] {default [-127 0 30 0]} @@ -22,27 +22,38 @@ % {default|0 -> +/-abs max of data} % startsec = starting time in seconds {default|0 -> 0.0} % -% Note: BUG IN MATLAB 5.0-5.1 -- CANT SHOW MOVIES IN CORRECT COLORS +% Note: BUG IN MATLAB 5.0-5.1 -- CAN'T SHOW MOVIES IN CORRECT COLORS % % Authors: Scott Makeig & Colin Humphries, SCCN/INC/UCSD, La Jolla, 2/1998 % -% See also: seemovie(), eegmovie(), headplot() +% See also: SEEMOVIE, EEGMOVIE, HEADPLOT % Copyright (C) 2.6.98 Scott Makeig & Colin Humphries, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license, added links -ad @@ -64,7 +75,7 @@ if nargin<8 minmax = 0; end -if size(minmax)==[1 1] & minmax ~= 0 +if size(minmax)==[1 1] && minmax ~= 0 minmax = [-minmax minmax]; end if minmax ==0, @@ -102,7 +113,7 @@ eloc_file = 0; end -if movieframes(1) < 1 | movieframes(length(movieframes))>frames +if movieframes(1) < 1 || movieframes(length(movieframes))>frames fprintf('headmovie(): specified movieframes not in data!\n'); return end @@ -130,7 +141,7 @@ help headmovie return end -if size(camerapath,1) > 1 & size(camerapath,2)~=4 +if size(camerapath,1) > 1 && size(camerapath,2)~=4 help headmovie return end @@ -150,7 +161,7 @@ figure(gcf); % bring figure to front clf % clear figure -%%%%%%%%%%%%%%%%%%%%% eegplot() of data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%% EEGPLOT of data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% axeegplot = axes('Units','Normalized','Position',[.75 .05 .2 .9]); if isstruct(eloc_file) diff --git a/functions/miscfunc/help2html2.m b/functions/miscfunc/help2html2.m index a7e469e8c..bffe3370c 100644 --- a/functions/miscfunc/help2html2.m +++ b/functions/miscfunc/help2html2.m @@ -1,4 +1,4 @@ -% help2html() - Convert a Matlab m-file help-message header into an .html help file +% HELP2HTML - Convert a Matlab m-file help-message header into an .html help file % % Usage: % >> linktext = help2html( filein, fileout, 'key1', val1, 'key2', val2 ...); @@ -34,7 +34,7 @@ % to allow .html help file generation. Characters '-' and ':' are used % explicitly by the function for parsing. % -%% function_name() - description line 1 +%% FUNCTION_NAME - description line 1 %% description line 2 %% etc. %% @@ -50,7 +50,7 @@ %% text line 2 %% %% See also: -%% function1(), function2() +%% FUNCTION1, FUNCTION2 % % Author: Arnaud Delorme, Salk Institute 2001 % @@ -61,7 +61,7 @@ % each descriptor (i.e., single_word followed by '-' or '=' % or multiple quoted words followed by a '-' or '=') % are concatenated. -% 2) The pattern 'function()' is detected and is printed in bold +% 2) The pattern 'FUNCTION' is detected and is printed in bold % if it is the first function descriptor. Otherwise, % it is used as a web link to the .html function file % 'function.html' if this exists. @@ -75,33 +75,44 @@ % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 [linktext,allvars,alltext] = help2html( filename, htmlfile, varargin) if nargin < 1 help help2html; return; -end; +end if nargin <3 g = []; else g = struct( varargin{:});; end; -try, g.font; catch, g.font = 'Helvetica'; end; +try, g.font; catch, g.font = 'Helvetica'; end g.functionname = [ '%s' ]; g.description = [ '%s' ]; @@ -116,8 +127,8 @@ g.doublecol = ''; g.seefile = [ 'See the matlab file %s (may require other functions)

' ]; -try, g.outputonly; catch, g.outputonly = 'off'; end; -try, g.background; catch, g.background = ''; end; +try, g.outputonly; catch, g.outputonly = 'off'; end +try, g.background; catch, g.background = ''; end try, g.header; catch, g.header = ''; end; try, g.footer; catch, g.footer = ''; end; try, g.refcall; catch, g.refcall = '%s.html'; end; @@ -132,29 +143,29 @@ % output file % ----------- -if nargin < 2 | isempty(htmlfile); +if nargin < 2 || isempty(htmlfile); indexdot = findstr( filename, '.'); - if isempty(indexdot), indexdot = length(filename)+1; end; + if isempty(indexdot), indexdot = length(filename)+1; end htmlfile = [ filename(1:indexdot(end)-1) '.html' ]; else indexdot = findstr( filename, '.'); -end; +end % open files % ---------- fid = fopen( filename, 'r'); if fid == -1 error('Input file not found'); -end; +end if ~strcmp(g.outputonly, 'on') fo = fopen(htmlfile, 'w'); if fo == -1 error('Cannot open output file'); - end; + end % write header % ------------ fprintf(fo, '%s\n%s\n\n', g.header, g.background); -end; +end cont = 1; @@ -193,9 +204,9 @@ switch lower(str(1:i2d)) case { 'usage:' 'authors:' 'author:' 'notes:' 'note:' 'input:' ... 'inputs:' 'outputs:' 'output:' 'example:' 'examples:' 'see also:' }, newtitle = 1; - end; - if (i2d == length(str)) & (str(1) ~= '%'), newtitle = 1; end; - end; + end + if (i2d == length(str)) && (str(1) ~= '%'), newtitle = 1; end; + end if newtitle tilehtml = str(1:i2d); newtitle = 1; @@ -213,7 +224,7 @@ [tok1 strrm] = mystrtok( str ); [tok2 strrm] = strtok( strrm ); - if ~isempty(tok2) & ( tok2 == '-' | tok2 == '=') % new variable + if ~isempty(tok2) && ( tok2 == '-' || tok2 == '=') % new variable newvar = 1; oldvarname = varname; oldvartext = vartext; @@ -221,7 +232,7 @@ varname = formatstr( tok1, g.refcall); else varname = tok1; - end; + end strrm = deblank(strrm); % remove tail blanks strrm = deblank(strrm(end:-1:1)); % remove initial blanks strrm = formatstr( strrm(end:-1:1), g.refcall); @@ -235,18 +246,18 @@ vartext = str; else if ~isempty(varname) - vartext = [ vartext ' ' str]; % espace if in array + vartext = [ vartext ' ' str]; % space if in array else if all(vartext( end-2:end) == '.') - vartext = [ deblank2(vartext(1:end-3)) ' ' str]; % espace if '...' + vartext = [ deblank2(vartext(1:end-3)) ' ' str]; % space if '...' else vartext = [ vartext '
' str]; % CR otherwise end; end; - end; + end end; newtitle = 0; - end; + end % --- END OF DECODING str = fgets( fid ); @@ -264,7 +275,7 @@ else if ~isempty(oldvartext) fprintf( fo, [ g.normcol2 g.text '\n' ], finalformat(oldvartext)); - end; + end end; newvar = 1; oldvarname = varname; @@ -274,7 +285,7 @@ % test if new input for an array % ------------------------------ - if newvar | newtitle + if newvar || newtitle if maindescription if ~isempty(oldvartext) % FUNCTION TITLE maintext = oldvartext; @@ -282,12 +293,12 @@ % generate the output command % --------------------------- try, g.outputtext; catch, g.outputtext = ''; end; - if isempty(g.outputtext), g.outputtext = filename(1:indexdot(end)-1); end; + if isempty(g.outputtext), g.outputtext = filename(1:indexdot(end)-1); end linktext = sprintf( g.outputlink, g.outputtext, filename(1:indexdot(end)-1), maintext ); if strcmp(g.outputonly, 'on') fclose(fid); return; - end; + end maindescription = 0; functioname = oldvarname( 1:findstr( oldvarname, '()' )-1); @@ -310,9 +321,9 @@ fprintf(fo, [ g.normrow g.doublecol ... '

' ]); - end; + end - end; + end end; elseif ~isempty(oldvarname) allvars{indexout} = oldvarname; @@ -323,7 +334,7 @@ else if ~isempty(oldvartext) fprintf( fo, [ g.normcol2 g.text '\n' ], finalformat(oldvartext)); - end; + end end; end; @@ -336,11 +347,11 @@ end; oldvarname = []; oldvartext = []; - end; + end else str = fgets( fid ); - end; -end; + end +end fprintf( fo, [ '
\n
' g.seefile '%s'], lower(filename), filename, g.footer); fclose( fid ); fclose( fo ); @@ -366,52 +377,52 @@ strout = [strout ' ' tokout ]; end; [tok1 strrm] = strtok( strrm ); - end; + end return; -% final formating +% final formatting function str = finalformat(str); % bold text in bracket if just in the beginning tmploc = sort(union(find(str == '['), find(str == ']'))); - if ~isempty(tmploc) & str(1) == '[' - if mod(length(tmploc),2) ~= 0, str, error('Opening but no closing bracket'); end; + if ~isempty(tmploc) && str(1) == '[' + if mod(length(tmploc),2) ~= 0, str, error('Opening but no closing bracket'); end tmploc = tmploc(1:2); str = [ str(1:tmploc(1)) '' str(tmploc(1)+1:tmploc(2)-1) '' str(tmploc(2):end) ]; - end; + end %tmploc = find(str == '"'); %if ~isempty(tmploc) - % if mod(length(tmploc),2) ~= 0, str, error('Opening but no closing parenthesis'); end; + % if mod(length(tmploc),2) ~= 0, str, error('Opening but no closing parenthesis'); end % for index = length(tmploc):-2:1 % str = [ str(1:tmploc(index-1)-1) '' str(tmploc(index-1)+1:tmploc(index)-1) '' str(tmploc(index)+1:end) ]; - % end; - %end; + % end + %end function tokout = functionformat( tokin, refcall ); tokout = tokin; % default [test, realtokin, tail, beg] = testfunc1( tokin ); - if ~test, [test, realtokin, tail] = testfunc2( tokin ); end; + if ~test, [test, realtokin, tail] = testfunc2( tokin ); end if test i1 = findstr( refcall, '%s'); i2 = findstr( refcall(i1(1):end), ''''); - if isempty(i2) i2 = length( refcall(i1(1):end) )+1; end; + if isempty(i2) i2 = length( refcall(i1(1):end) )+1; end filename = [ realtokin refcall(i1+2:i1+i2-2)]; % concatenate filename and extension %disp(filename) if exist( filename ) % do not make link if the file does not exist tokout = sprintf( [ beg '%s' tail ' ' ], realtokin, realtokin ); - end; + end end; return; function [test, realtokin, tail, beg] = testfunc1( tokin ) % test if is string is 'function()[,]' test = 0; realtokin = ''; tail = ''; beg = ''; if ~isempty( findstr( tokin, '()' ) ) - if length(tokin)<3, return; end; + if length(tokin)<3, return; end realtokin = tokin( 1:findstr( tokin, '()' )-1); - if length(realtokin) < (length(tokin)-2) tail = tokin(end); else tail = []; end; + if length(realtokin) < (length(tokin)-2) tail = tokin(end); else tail = []; end test = 1; - if realtokin(1) == '(', realtokin = realtokin(2:end); beg = '('; end; - if realtokin(1) == ',', realtokin = realtokin(2:end); beg = ','; end; - end; + if realtokin(1) == '(', realtokin = realtokin(2:end); beg = '('; end + if realtokin(1) == ',', realtokin = realtokin(2:end); beg = ','; end + end return; function [test, realtokin, tail] = testfunc2( tokin ) % test if is string is 'FUNCTION[,]' @@ -422,15 +433,15 @@ tail = ','; else realtokin = tokin; - end; + end testokin = realtokin; testokin(findstr(testokin, '_')) = 'A'; testokin(findstr(testokin, '2')) = 'A'; - if all(double(testokin) > 64) & all(double(testokin) < 91) + if all(double(testokin) > 64) && all(double(testokin) < 91) test = 1; end; realtokin = lower(realtokin); - end; + end return; function [tok, str] = mystrtok(str) @@ -439,8 +450,8 @@ if tok(1) == '"' while tok(end) ~= '"' [tok2 str] = strtok(str); - if isempty(tok2), tok, error('can not find closing quote ''"'' in previous text'); end; + if isempty(tok2), tok, error('can not find closing quote ''"'' in previous text'); end tok = [tok ' ' tok2]; - end; - end; + end + end diff --git a/functions/miscfunc/helpforexe.m b/functions/miscfunc/helpforexe.m index 06df583ad..097d82526 100644 --- a/functions/miscfunc/helpforexe.m +++ b/functions/miscfunc/helpforexe.m @@ -1,4 +1,4 @@ -% helpforexe() - Write help files for exe version +% HELPFOREXE - Write help files for exe version % % Usage: % histtoexe( mfile, folder) @@ -12,30 +12,41 @@ % % Author: Arnaud Delorme, 2006 % -% See also: eeglab() +% See also: EEGLAB % Copyright (C) 2006 Arnaud Delorme % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 helpforexe( funct, fold ); if nargin <1 help histforexe; return; -end; +end nonmatlab = 0; % write all files @@ -47,11 +58,11 @@ for ind2 = 1:length(doc1) if isempty(doc1{ind2}) fprintf(fid, [ 'disp('' '');\n' ]); else fprintf(fid, [ 'disp(' vararg2str({ doc1{ind2} }) ');\n' ]); - end; - end; + end + end fclose(fid); %fprintf(fid, 'for tmpind = 1:length(tmptxt), if isempty(tmptxt{tmpind}), disp('' ''); else disp(tmptxt{tmpind}); end; end; clear tmpind tmptxt;\n' ); -end; +end % try all functions % ----------------- @@ -59,7 +70,7 @@ cd(fold); for index = 1:length(funct) evalc([ 'help_' funct{index}(1:end-2) ]); -end; +end cd(tmppath); return; @@ -74,17 +85,17 @@ fid = fopen( funct, 'r'); else fid = fopen( [funct '.m'], 'r'); - end; -end; + end +end if fid == -1 error('File not found'); -end; +end sub = 1; try, - if ~isunix, sub = 0; end; -catch, end; + if ~isunix, sub = 0; end +catch, end if nonmatlab str = fgets( fid ); @@ -92,13 +103,13 @@ str = deblank(str(1:end-sub)); doc = { doc{:} str(1:end) }; str = fgets( fid ); - end; + end else str = fgets( fid ); while (str(1) == '%') str = deblank(str(1:end-sub)); doc = { doc{:} str(2:end) }; str = fgets( fid ); - end; -end; + end +end fclose(fid); diff --git a/functions/miscfunc/hist2.m b/functions/miscfunc/hist2.m index 7d97c7320..da6d61140 100644 --- a/functions/miscfunc/hist2.m +++ b/functions/miscfunc/hist2.m @@ -1,4 +1,4 @@ -% hist2() - draw superimposed histograms +% HIST2 - draw superimposed histograms % % Usage: % >> hist2(data1, data2, bins); @@ -14,19 +14,30 @@ % Copyright (C) 2003 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % draw superimposed histograms @@ -36,12 +47,12 @@ if nargin < 1 help hist2; return; -end; +end if nargin < 3 bins = linspace(min(min(data1), min(data2)), max(max(data1), max(data2)), 100); elseif length(bins) == 1 bins = linspace(min(min(data1), min(data2)), max(max(data1), max(data2)), bins); -end; +end hist(data1, bins); hold on; hist(data2, bins); diff --git a/functions/miscfunc/hungarian.m b/functions/miscfunc/hungarian.m index 5713ff467..a35ab1131 100644 --- a/functions/miscfunc/hungarian.m +++ b/functions/miscfunc/hungarian.m @@ -1,4 +1,5 @@ -% hungarian() - Solve the assignment problem using the Hungarian method. +function [C,T]=hungarian(A) +% HUNGARIAN - Solve the assignment problem using the Hungarian method. % % Usage: >> [C,T]=hungarian(A) % @@ -14,15 +15,13 @@ % Mathematical Software, 6(1):104-111, 1980. % % v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se. -% Department of Computing Science, Umeå University, +% Department of Computing Science, Ume University, % Sweden. % % NOTE: A substantial effort was put into this code. If you use it for a % publication or otherwise, please include an acknowledgement and notify % me by email. /Niclas -function [C,T]=hungarian(A) - [m,n]=size(A); if (m~=n) @@ -65,7 +64,7 @@ % If there are more free zeros in row r and row r in not % yet marked as unexplored.. - if (A(r,l)~=0 & RH(r)==0) + if (A(r,l)~=0 && RH(r)==0) % Insert row r first in unexplored list. RH(r)=RH(n+1); RH(n+1)=r; @@ -200,7 +199,7 @@ [n,np1]=size(A); -% Initalize return vectors. +% Initialize return vectors. C=zeros(1,n); U=zeros(1,n+1); diff --git a/functions/miscfunc/icademo.m b/functions/miscfunc/icademo.m index ed102ebab..47ff7cd72 100644 --- a/functions/miscfunc/icademo.m +++ b/functions/miscfunc/icademo.m @@ -1,4 +1,4 @@ -% icademo() - a sample ICA analysis script using the ICA/ERP package +% ICADEMO - a sample ICA analysis script using the ICA/ERP package % of Matlab functions distributed via % http://www.sccn.ucsd.edu/eeglab % @@ -8,37 +8,48 @@ % % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 5-18-97 % -% See also: runica(), icavar(), icaproj(), icaact() +% See also: RUNICA, ICAVAR, ICAPROJ, ICAACT % Copyright (C) 5-18-97 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % This version tested on package version -% Added envproj(), used maxmap in compplot() 6-18-97 -sm +% Added ENVPROJ, used maxmap in COMPPLOT 6-18-97 -sm % Reworked to use actual sample ERP data 6-27-97 -sm % Pruned again 7/18/97 -sm % Adjusted envproj, plotproj, icaproj to remove datamean, distributing % mean offset (if any) among component projections 7/23/97 -sm -% Fixed plotproj() call - it can't label arbitrry channel lists -sm +% Fixed PLOTPROJ call - it can't label arbitrry channel lists -sm % Adjusted envproj etc. 12/08/97 -sm -% Added timtopo() 1-16-98 -sm +% Added TIMTOPO 1-16-98 -sm % Added more formatting, fixed compplot and eegmovie plotting 10-9-99 -sm % 12-19-00 revised icaproj args -sm -% 01-05-01 advertised the web tutorial, fixed chanproj(), improved eegmovie() -sm -% 01-12-01 removed 'sphere' arg from plotproj(), icaact() -sm +% 01-05-01 advertised the web tutorial, fixed CHANPROJ, improved EEGMOVIE -sm +% 01-12-01 removed 'sphere' arg from PLOTPROJ, ICAACT -sm % 01-25-02 reformated help & license, added links -ad chans = 14; % data channels (rows in data matrix) @@ -72,7 +83,7 @@ p = which('eeglab'); p = p(1:findstr(p,'eeglab.m')-1); addpath([ p 'sample_data' ] ); -end; +end % name of channel locations file chan_locs = 'pnas_chan14.locs'; @@ -99,7 +110,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Load an ascii ERP data matrix @@ -129,7 +140,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -147,7 +158,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -163,7 +174,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -178,7 +189,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -197,7 +208,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -219,7 +230,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -235,7 +246,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end [weights,sphere,activations,bias,signs,lrates] = runica(data); @@ -243,7 +254,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -274,11 +285,11 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Plot the activation waveforms of all the components -% as reordered by compsort() +% as reordered by COMPSORT % Identify the components using the original component numbers. % fprintf('Plotting the component activation waveforms using plotdata()') @@ -291,7 +302,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Plot the contributions to the first epoch of data by the first reordered @@ -308,7 +319,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Plot the contributions to the first epoch of data by the 5 largest @@ -326,7 +337,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Plot the envelopes of the data epoch 1 and the first 10 components @@ -343,7 +354,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % fprintf('Now plotting envelopes PLUS scalp maps using envtopo().\n'); @@ -357,7 +368,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Plot a close-up of the decomposition of epoch 2, channel 2. @@ -378,7 +389,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Plot the scalp maps of the first four reordered components @@ -393,7 +404,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Display the projected epoch-1 data for reordered ICA component windex(7) @@ -412,7 +423,7 @@ if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Make and display a brief movie of a small segment of the first data epoch @@ -431,11 +442,11 @@ seemovie(Movie,-5,Colormap); catch, disp('Problem generating movie'); -end; +end if ~exist('icademoauto') fprintf('\n****> Hit any key to continue: '); pause; fprintf('\n\n'); %%% -end; +end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Run testica script using optimum parameters @@ -454,7 +465,7 @@ testica(chans,epochs*frames,14,-0.05,1.4); else [testresult] = testica(chans,epochs*frames,14,-0.05,1.4); -end; +end % model 14 sources with a wide range of sizes & positive kurtosis diff --git a/functions/miscfunc/imagescloglog.m b/functions/miscfunc/imagescloglog.m index 5d09fa8e3..f10255f49 100644 --- a/functions/miscfunc/imagescloglog.m +++ b/functions/miscfunc/imagescloglog.m @@ -1,4 +1,4 @@ -% imagescloglog() - make an imagesc(0) plot with log y-axis and +% IMAGESCLOGLOG - make an imagesc(0) plot with log y-axis and % x-axis values % % Usage: >> imagescloglog(times,freqs,data); @@ -19,19 +19,30 @@ % Copyright (C) 4/2003 Arnaud Delorme, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 imagescloglog(times,freqs,data,clim, xticks, yticks, varargin) @@ -77,16 +88,16 @@ function imagescloglog(times,freqs,data,clim, xticks, yticks, varargin) border = mean(newfreqs(2:end)-newfreqs(1:end-1))/2; % automatically added to the borders in imagesc newfreqs = linspace(realborders(1)+border, realborders(2)-border, length(freqs)); - if nargin == 4 & ~isempty(clim) + if nargin == 4 && ~isempty(clim) imagesc(newtimes,newfreqs,data,clim); else imagesc(newtimes,newfreqs,data); - end; + end set(gca, 'yscale', 'log', 'xscale', 'log'); - try colormap(DEFAULT_COLORMAP); catch, end; + try colormap(DEFAULT_COLORMAP); catch, end - % puting ticks + % putting ticks % ------------ if nargin >= 5 divs = xticks; @@ -94,7 +105,7 @@ function imagescloglog(times,freqs,data,clim, xticks, yticks, varargin) divs = linspace(log(times(1)), log(times(end)), 10); divs = ceil(exp(divs)); divs = unique_bc(divs); % ceil is critical here, round might misalign % out-of border label with within border ticks - end; + end set(gca, 'xtickmode', 'manual'); set(gca, 'xtick', divs); if nargin >= 6 @@ -103,7 +114,7 @@ function imagescloglog(times,freqs,data,clim, xticks, yticks, varargin) divs = linspace(log(freqs(1)), log(freqs(end)), 10); divs = ceil(exp(divs)); divs = unique_bc(divs); % ceil is critical here, round might misalign % out-of border label with within border ticks - end; + end set(gca, 'ytickmode', 'manual'); set(gca, 'ytick', divs); @@ -112,5 +123,5 @@ function imagescloglog(times,freqs,data,clim, xticks, yticks, varargin) set(gca, 'yminortick', 'off', 'xaxislocation', 'bottom', 'box', 'off', 'ticklength', [0.03 0], 'tickdir','out', 'color', 'none'); if ~isempty(varargin) set(gca, varargin{:}); - end; + end diff --git a/functions/miscfunc/imagesclogy.m b/functions/miscfunc/imagesclogy.m index 8ce9015b3..742db311a 100644 --- a/functions/miscfunc/imagesclogy.m +++ b/functions/miscfunc/imagesclogy.m @@ -1,4 +1,4 @@ -% imagesclogy() - make an imagesc(0) plot with log y-axis values (ala semilogy()) +% IMAGESCLOGY - make an imagesc(0) plot with log y-axis values (ala SEMILOGY) % % Usage: >> imagesclogy(times,freqs,data); % Usage: >> imagesclogy(times,freqs,data,clim,xticks,yticks,'key','val',...); @@ -18,19 +18,30 @@ % Copyright (C) 4/2003 Arnaud Delorme, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 imagesclogy(times,freqs,data,clim, xticks, yticks, varargin) @@ -63,23 +74,23 @@ function imagesclogy(times,freqs,data,clim, xticks, yticks, varargin) border = mean(newfreqs(2:end)-newfreqs(1:end-1))/2; % automatically added to the borders in imagesc newfreqs = linspace(realborders(1)+border, realborders(2)-border, length(freqs)); - if nargin == 4 & ~isempty(clim) + if nargin == 4 && ~isempty(clim) imagesc(times,newfreqs,data,clim); else imagesc(times,newfreqs,data); - end; + end set(gca, 'yscale', 'log'); - % puting ticks + % putting ticks % ------------ - if nargin >= 5, set(gca, 'xtick', xticks); end; + if nargin >= 5, set(gca, 'xtick', xticks); end if nargin >= 6 divs = yticks; else divs = linspace(log(freqs(1)), log(freqs(end)), 10); divs = ceil(exp(divs)); divs = unique_bc(divs); % ceil is critical here, round might misalign % out-of border label with within border ticks - end; + end set(gca, 'ytickmode', 'manual'); set(gca, 'ytick', divs); @@ -88,5 +99,5 @@ function imagesclogy(times,freqs,data,clim, xticks, yticks, varargin) set(gca, 'yminortick', 'off', 'xaxislocation', 'bottom', 'box', 'off', 'ticklength', [0.03 0], 'tickdir','out', 'color', 'none'); if ~isempty(varargin) set(gca, varargin{:}); - end; + end diff --git a/functions/miscfunc/iscellnumeric.m b/functions/miscfunc/iscellnumeric.m deleted file mode 100644 index 724cb7959..000000000 --- a/functions/miscfunc/iscellnumeric.m +++ /dev/null @@ -1,6 +0,0 @@ -function b = iscellnumeric(C) -% Return 1 if all elements of cell array are numeric -% -% Tim Mullen, 2011, SCCN/INC, UCSD - -b = all(cellfun(@(x) isnumeric(x),C)); diff --git a/functions/miscfunc/kmeans_st.m b/functions/miscfunc/kmeans_st.m index bc51ef4dc..71190c77f 100644 --- a/functions/miscfunc/kmeans_st.m +++ b/functions/miscfunc/kmeans_st.m @@ -1,3 +1,4 @@ +function [centr,clst,sse] = kmeans_st(X,k,restarts) % KMEANS: K-means clustering of n points into k clusters so that the % within-cluster sum of squares is minimized. Based on Algorithm % AS136, which seeks a local optimum such that no movement of a @@ -26,20 +27,19 @@ % RE Strauss, 8/26/98 % 8/21/99 - changed misc statements for Matlab v5. -% 10/14/00 - use means() rather than mean() to update cluster centers; +% 10/14/00 - use MEANS rather than MEAN to update cluster centers; % remove references to TRUE and FALSE. -function [centr,clst,sse] = kmeans_st(X,k,restarts) - if (nargin<3) restarts = []; end; + if (nargin<3) restarts = []; end if (isempty(restarts)) restarts = 0; - end; + end [n,p] = size(X); - if (k<1 | k>n) + if (k<1 || k>n) error('KMEANS: k out of range 1-N'); - end; + end max_iter = 50; highval = 10e8; @@ -74,7 +74,7 @@ grp(indx) = t3 * ones(length(indx),1); indx = find(grp==t2); grp(indx) = t3 * ones(length(indx),1); - end; + end grpid = uniquef(grp); % Unique group identifiers centr = zeros(k,p); @@ -86,13 +86,13 @@ centr(kk,:) = mean(Xk); else centr(kk,:) = Xk; - end; - end; + end + end else % Else if randomized, rndprm = randperm(n); % Pull out random set of points centr = X(rndprm(1:k),:); - end; + end % For each point i, find its two closest centers, c1(i) and c2(i), and % assign it to c1(i) @@ -100,7 +100,7 @@ dist = zeros(n,k); for kk = 1:k % Dists to centers of all clusters dist(:,kk) = eucl(X,centr(kk,:)); - end; + end [d,indx] = sort(dist'); % Sort points separately c1 = indx(1,:)'; @@ -115,10 +115,10 @@ % centr(kk,:) = mean(X(indx,:)); % else % centr(kk,:) = X(indx,:); -% end; +% end centr(kk,:) = means(X(indx,:)); nclst(kk) = len_indx; - end; + end % Initialize working matrices @@ -131,7 +131,7 @@ for i = 1:n % Adjusted dist from each pt to own cluster center R1(i) = adj2(c1(i)) * eucl(X(i,:),centr(c1(i),:))^2; - end; + end % Iterate @@ -157,7 +157,7 @@ indx = find(~live); % find min R2 over live clusters only R2([L1;indx]) = highval * ones(length(indx)+1,1); [r2min,L2] = min(R2); - end; + end if (r2min >= R1(i)) % No reallocation necessary c2(i) = L2; @@ -172,9 +172,9 @@ centr(kk,:) = mean(X(indx,:)); else centr(kk,:) = X(indx,:); - end; + end nclst(kk) = len_indx; - end; + end adj1([L1,L2]) = nclst([L1,L2]) ./ (nclst([L1,L2])+1); adj2([L1,L2]) = nclst([L1,L2]) ./ (nclst([L1,L2])-1+eps); @@ -182,13 +182,13 @@ live([L1,L2]) = [1,1]; % Put into live set update([L1,L2]) = [n,n]; % Reinitialize update counters - end; + end end; % if nclst(L1)>1 indx = find(update<1); % Remove clusters from live set if (~isempty(indx)) % that haven't been recently updated live(indx) = zeros(length(indx),1); - end; + end end; % while (i 0) clst = best_c1; diff --git a/functions/miscfunc/laplac2d.m b/functions/miscfunc/laplac2d.m index 43417bde1..a1749e3a6 100644 --- a/functions/miscfunc/laplac2d.m +++ b/functions/miscfunc/laplac2d.m @@ -1,4 +1,4 @@ -% laplac2d() - generate a 2 dimensional gaussian matrice +% LAPLAC2D - generate a 2 dimensional laplacian matrice % % Usage : % >> [ gaussmatrix ] = laplac2d( rows, columns, sigma, ... @@ -10,7 +10,7 @@ % Inputs: % rows - number of rows % columns - number of columns -% sigma - standart deviation (default: rows/5) +% sigma - standard deviation (default: rows/5) % meanR - mean for rows (default: center of the row) % meanC - mean for columns (default: center of the column) % cut - percentage (0->1) of the maximum value for removing @@ -20,44 +20,55 @@ % research. For a more rigorous validated approach use the freely % available Current Source Density Matlab toolbox. % -% See also: eeg_laplac() +% See also: EEG_LAPLAC % % Author: Arnaud Delorme, CNL, Salk Institute, 2001 % Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 mat = laplac2d( sizeX, sizeY, sigma, meanX, meanY, cut); if nargin < 2 help laplac2d return; -end; +end if nargin < 3 sigma = sizeX/5; -end; +end if nargin < 4 meanX = (sizeX+1)/2; -end; +end if nargin < 5 meanY = (sizeY+1)/2; -end; +end if nargin < 6 cut = 0; -end; +end X = linspace(1, sizeX, sizeX)'* ones(1,sizeY); Y = ones(1,sizeX)' * linspace(1, sizeY, sizeY); @@ -71,9 +82,9 @@ % zeros crossing at r = -/+ sigma; % mat = r2; if cut > 0 - maximun = max(max(mat))*cut; - I = find(mat < maximun); + maximum = max(max(mat))*cut; + I = find(mat < maximum); mat(I) = 0; -end; +end return; diff --git a/functions/miscfunc/lapplot.m b/functions/miscfunc/lapplot.m index fb98d27d4..42056eb68 100644 --- a/functions/miscfunc/lapplot.m +++ b/functions/miscfunc/lapplot.m @@ -1,4 +1,4 @@ -% lapplot() - Compute the discrete laplacian of EEG scalp distribution(s) +% LAPPLOT - Compute the discrete laplacian of EEG scalp distribution(s) % % Usage: % >> laplace = lapplot(map,eloc_file,draw) @@ -12,27 +12,38 @@ % Output: % laplace - Laplacian map, size (nelectrodes,nmaps) % -% Note: uses del2() +% Note: uses DEL2 % % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 1998 % -% See also: topoplot(), gradplot() +% See also: TOPOPLOT, GRADPLOT % Copyright (C) Scott Makeig, SCCN/INC/UCSD, La Jolla, 1998 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license, added links -ad @@ -41,7 +52,7 @@ if nargin < 2 help lapplot; return; -end; +end MAXCHANS = size(map,1); GRID_SCALE = 2*MAXCHANS+5; @@ -50,7 +61,7 @@ % --------------------- % Read the channel file % --------------------- -if isstr( filename ) +if ischar( filename ) fid = fopen(filename); locations = fscanf(fid,'%d %f %f %s',[7 MAXCHANS]); fclose(fid); @@ -74,7 +85,7 @@ for i=1:MAXCHANS [useless_var horizidx(i)] = min(abs(y(i) - xi)); % find pointers to electrode [useless_var vertidx(i)] = min(abs(x(i) - yi)); % positions in Zi -end; +end % ----------------- % Compute laplacian @@ -131,7 +142,7 @@ hold off axis off - end; + end end; return; diff --git a/functions/miscfunc/loadelec.m b/functions/miscfunc/loadelec.m index eb802287d..59143cd9d 100644 --- a/functions/miscfunc/loadelec.m +++ b/functions/miscfunc/loadelec.m @@ -1,26 +1,37 @@ -% loadelec() - Load electrode names file for eegplot() +% LOADELEC - Load electrode names file for EEGPLOT % % Usage: >> labelmatrix = loadelec('elec_file'); % % Author: Colin Humprhies, CNL / Salk Institute, 1996 % -% See also: eegplot() +% See also: EEGPLOT % Copyright (C) Colin Humphries, CNL / Salk Institute, Aug, 1996 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license, added links -ad @@ -34,7 +45,7 @@ % Read the channel names %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if channamefile ~= 0 & channamefile ~= '0' % read file of channel names +if channamefile ~= 0 && channamefile ~= '0' % read file of channel names chid = fopen(channamefile,'r'); if chid <3, fprintf('cannot open file %s.\n',channamefile); @@ -42,7 +53,7 @@ channamefile = 0; else fprintf('Channamefile %s opened\n',channamefile); - end; + end if errorcode==0, channames = fscanf(chid,'%s',[6 MAXCHANS]); channames = channames'; @@ -51,20 +62,20 @@ for j=1:c if channames(i,j)=='.', channames(i,j)=' '; - end; - end; - end; + end + end + end % fprintf('%d channel names read from file.\n',r); if (r>chans) fprintf('Using first %d names.\n',chans); channames = channames(1:chans,:); - end; + end if (r length(chanlocs) error('Total channels in requested subsets larger than number of EEG channels.'); -end; +end if min(numberOfChannelsInSubset) < 2 error('Number of channels in the requested subsets must be >= 2.'); -end; +end rand('state',0); if nargin < 5 mandatoryChannelsForSet = {}; -end; +end if nargin < 4 plotSubsets = false; -end; +end if nargin < 3 plotOptimization = false; -end; +end pos=[cell2mat({chanlocs.X}); cell2mat({chanlocs.Y}); cell2mat({chanlocs.Z});]; dist = squareform(pdist(pos')); @@ -95,7 +106,7 @@ idx = ones(nChans,1); setId = cell(1, length(numberOfChannelsInSubset)); % cell array containing channels in each set -remainingChannels = 1:nChans; % channles that are to be assigned to subsets +remainingChannels = 1:nChans; % channels that are to be assigned to subsets % channels that have to stay in their original subset (as in % mandatoryChannelsForSet) and should not be re-assigned @@ -105,7 +116,7 @@ for i=1:length(mandatoryChannelsForSet) setId{i} = mandatoryChannelsForSet{i}; remainingChannels(mandatoryChannelsForSet{i}) = NaN; % flag with Nan so they can be deleted later, this is to keep indexing simple -end; +end remainingChannels(isnan(remainingChannels)) = []; r = remainingChannels(randperm(length(remainingChannels))); @@ -115,11 +126,11 @@ numberOfChannelsTobeAddedToSubset = numberOfChannelsInSubset(i) - length(setId{i}) setId{i} = [setId{i} r(1:numberOfChannelsTobeAddedToSubset)]; r(1:numberOfChannelsTobeAddedToSubset) = []; -end; +end if length(r) > 0 setId{length(numberOfChannelsInSubset) + 1} = r; % last set gets remaining channels -end; +end if plotOptimization|plotSubsets fprintf(['Creating total of ' num2str(length(setId)) ' channel subsets:\n']); @@ -129,7 +140,7 @@ figure; xp = floor(sqrt(length(setId))); yp = ceil(length(setId)/xp); -end; +end counter = 1; exchangeHappened = true; @@ -142,14 +153,14 @@ for j = 1:length(setId{set2}) chan(1) = setId{set1}(i); chan(2) = setId{set2}(j); - if cost_of_exchanging_channels(chan,[set1 set2], setId, dist) < 0 & ~ismember(chan, allMandatoryChannels) + if cost_of_exchanging_channels(chan,[set1 set2], setId, dist) < 0 && ~any(ismember(chan, allMandatoryChannels)) setId{set1}(find(setId{set1} == chan(1))) = chan(2); setId{set2}(find(setId{set2} == chan(2))) = chan(1); sumDistances(counter) = 0; for s = 1:length(setId) sumDistances(counter) = sumDistances(counter) ... + (sum(sum(dist(setId{s},setId{s}))) / length(setId{s})); - end; + end if plotOptimization plot(1:counter,sumDistances,'-b'); xlabel('number of exchanges'); @@ -159,21 +170,21 @@ if mod(counter, 20) ==0 fprintf('number of exchanges = %d\nsum of mean distances = %g\n',... counter, sumDistances(counter)); - end; + end end counter = counter + 1; exchangeHappened = true; - end; - end; - end; - end; - end; -end; + end + end + end + end + end +end for set = 1:length(setId) idx(setId{set}) = set; % legendTitle{set} = ['subset ' num2str(set)]; -end; +end subset = setId; @@ -186,9 +197,9 @@ %legend(legendTitle); it does not work propr th=title('Channel Subsets'); %set(th,'fontsize',14) -end; +end -if length(r)>0 & (plotOptimization|plotSubsets) +if length(r)>0 && (plotOptimization|plotSubsets) fprintf('The last subset returned contains the %d unused channels.\n',... length(r)); end @@ -201,14 +212,14 @@ for i=1:2 newSetId{betweenSets(i)} = setId{betweenSets(i)}; newSetId{betweenSets(i)}(find(newSetId{betweenSets(i)} == chan(i))) = chan(mirrorChan(i)); -end; +end cost = 0; for i=betweenSets distSumBefore{i} = sum(sum(dist(setId{i},setId{i}))); distSumAfter{i} = sum(sum(dist(newSetId{i},newSetId{i}))); cost = cost + (distSumBefore{i} - distSumAfter{i}) / length(setId{i}); -end; +end %cost = (distSumAfter{1} > distSumBefore{1}) && (distSumAfter{2} > distSumBefore{2}); diff --git a/functions/miscfunc/logimagesc.m b/functions/miscfunc/logimagesc.m index 0f5f37053..00aca02a1 100644 --- a/functions/miscfunc/logimagesc.m +++ b/functions/miscfunc/logimagesc.m @@ -1,4 +1,4 @@ -% logimagesc() - make an imagesc(0) plot with log y-axis values (ala semilogy()) +% LOGIMAGESC - make an imagesc(0) plot with log y-axis values (ala SEMILOGY) % % Usage: >> [logfreqs,dataout] = logimagesc(times,freqs,data); % @@ -10,25 +10,36 @@ % Optional Input: % plot = ['on'|'off'] plot image or return output (default 'on'). % -% Note: Entering text() onto the image requires specifying (x,log(y)). +% Note: Entering text onto the image requires specifying (x,log(y)). % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 4/2000 % Copyright (C) 4/2000 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 08-07-00 made ydir normal -sm % 01-25-02 reformated help & license -ad @@ -38,7 +49,7 @@ if nargin < 1 help logimagesc; return - end; + end if size(data,1) ~= length(freqs) fprintf('logfreq(): data matrix must have %d rows!\n',length(freqs)); datout = data; @@ -78,7 +89,7 @@ if strcmp(plot, 'on') imagesc(times,freqs,data); - try colormap(DEFAULT_COLORMAP); catch, end; + try colormap(DEFAULT_COLORMAP); catch, end nt = ceil(min(freqs)); % new tick - round up min y to int ht = floor(max(freqs)); % high freq - round down diff --git a/functions/miscfunc/loglike.m b/functions/miscfunc/loglike.m index db4d0af94..3e606065f 100644 --- a/functions/miscfunc/loglike.m +++ b/functions/miscfunc/loglike.m @@ -1,4 +1,5 @@ -% loglike() - log likehood function to estimate dependence between components +function f=loglike(W, S) +% LOGLIKE - log likehood function to estimate dependence between components % % Usage: f = loglike(W, S); % @@ -18,8 +19,6 @@ % % Author: Arnaud Delorme and Jorn Anemuller -function f=loglike(W, S); - W = double(W); S = double(S); % normalize activities @@ -30,7 +29,7 @@ M = size(W,1); if ndims(S) == 3 S = reshape(S, size(S,1), size(S,3)*size(S,2)); - end; + end N = size(S,2); % detect infinite and remove them diff --git a/functions/miscfunc/logspec.m b/functions/miscfunc/logspec.m index 2d98c8b40..091a1dc40 100644 --- a/functions/miscfunc/logspec.m +++ b/functions/miscfunc/logspec.m @@ -1,5 +1,5 @@ -% logspec() - plot mean log power spectra of submitted data on loglog scale -% using plotdata() or plottopo() formats +% LOGSPEC - plot mean log power spectra of submitted data on loglog scale +% using PLOTDATA or PLOTTOPO formats % % Usage: % >> [spectra,freqs] = logspec(data,frames,srate); @@ -12,31 +12,42 @@ % 'title' = plot title {default: none} % [loHz-hiHz] = [loHz hiHz] plotting limits % {default: [srate/fftlength srate/2]} -% 'chan_locs' = channel location file (ala topoplot()) +% 'chan_locs' = channel location file (ala TOPOPLOT) % Else [rows cols] to plot data in a grid array % rm_mean = [0/1] 1 -> remove log mean spectrum from all % % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 11-07-97 % -% See also: plotdata(), plottopo() +% See also: PLOTDATA, PLOTTOPO % Copyright (C) 11-07-97 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -% Changed plotdata() below to plottopo() 11/12/99 -sm +% 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. + +% Changed PLOTDATA below to PLOTTOPO 11/12/99 -sm % Mentioned new grid array option 12/22/99 -sm % 01-25-02 reformated help & license, added links -ad @@ -99,9 +110,9 @@ end for e=1:epochs - for r=1:rows, - [Pxx,freqs] = psd(data(r,(e-1)*frames+1:e*frames),fftlength,srate,... - fftlength,fftlength/4); + for r=1:rows + [Pxx,freqs] = pwelch(data(r,(e-1)*frames+1:e*frames),fftlength,... + fftlength/4,fftlength,srate); spectra(r,(e-1)*f2+1:e*f2) = Pxx(2:f2+1)'; % omit DC bin end end diff --git a/functions/miscfunc/make_timewarp.m b/functions/miscfunc/make_timewarp.m index ac2b9516b..b8b6df409 100644 --- a/functions/miscfunc/make_timewarp.m +++ b/functions/miscfunc/make_timewarp.m @@ -1,6 +1,6 @@ -% make_timewarp() - Select a subset of epochs containing a given event sequence, and return +% MAKE_TIMEWARP - Select a subset of epochs containing a given event sequence, and return % a matrix of latencies for time warping the selected epochs to a common -% timebase in newtimef(). Events in the given sequence may be further +% timebase in NEWTIMEF. Events in the given sequence may be further % restricted to those with specified event field values. % Usage: % >> timeWarp = make_timewarp(EEG, eventSequence, 'key1',value1, @@ -32,11 +32,11 @@ % from the mean in the selected epochs. {default: Inf -> no removal} % Outputs: % timeWarp - a structure with latencies (time-warp matrix with fields -% timeWarp.latencies - an (N, M) timewarp matrix for use in newtimef() +% timeWarp.latencies - an (N, M) timewarp matrix for use in NEWTIMEF % where N = number of selected epochs containing the specified sequence, % M = number of events in specified event sequence. % timeWarp.epochs - a (1, M) vector giving the index of epochs with the -% specified sequence. Only these epochs should be passed to newtimef(). +% specified sequence. Only these epochs should be passed to NEWTIMEF. % timeWarp.eventSequence - same as the 'eventSequence' input variable. % Example: % % Create a timewarp matrix for a sequence of events, first an event of type 'movement Onset' followed by @@ -52,7 +52,34 @@ % 'eventConditions', {'vx>0' 'vx>0 && vy<1'},'maxSTDForAbsolute', 3,'maxSTDForRelative', 2); % % Author: Nima Bigdely Shamlo, SCCN/INC/UCSD, 2008 -% See also: show_events(), newtimef() +% See also: SHOW_EVENTS, NEWTIMEF + +% Copyright (C) Nima Bigdely Shamlo, SCCN/INC/UCSD, 2008 +% +% 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 timeWarpStructure = make_timewarp(EEG, eventSequence, varargin) @@ -72,14 +99,14 @@ inputKeyValuesFields = fieldnames(inputKeyValues); for i=1:length(inputKeyValuesFields) eval([inputKeyValuesFields{i} '= inputKeyValues.' inputKeyValuesFields{i} ';']); -end; +end if length(eventConditions) < length(eventSequence) for i = (length(eventConditions)+1):length(eventSequence) eventConditions{i} = ''; - end; -end; + end +end epochsIsAcceptable = ones(1, length(EEG.epoch)); for epochNumber = 1:length(EEG.epoch) @@ -95,13 +122,13 @@ timeWarp{epochNumber} = [timeWarp{epochNumber}; firstLatency]; minimumLatency = firstLatency; eventNameID = eventNameID + 1; - end; - end; + end + end if length(timeWarp{epochNumber}) < length(eventSequence) epochsIsAcceptable(epochNumber) = false; - end; -end; + end +end acceptableEpochs = find(epochsIsAcceptable); @@ -115,14 +142,14 @@ timeWarp(:,rejectedEpochesBasedOnLateny) = []; acceptableEpochs(rejectedEpochesBasedOnLateny) = []; -end; +end % since latencies and accepted epochs always have to be together, we put them in one structure timeWarpStructure.latencies = timeWarp'; % make it suitable for newtimef() if isempty(timeWarpStructure.latencies) % when empty, it becomes a {} instead of [], so we change it to [] timeWarpStructure.latencies = []; -end; +end timeWarpStructure.epochs = acceptableEpochs; timeWarpStructure.eventSequence = eventSequence; @@ -134,7 +161,7 @@ rejectedBasedOnLateny = []; for eventNumber = 1:size(timeWarpDiff, 1) rejectedBasedOnLateny = [rejectedBasedOnLateny find(abs(timeWarpDiff(eventNumber, :)- mean(timeWarpDiff(eventNumber, :))) > maxSTDForRelative * std(timeWarpDiff(eventNumber, :)))]; - end; + end rejectedEpochesBasedOnLateny = unique_bc(rejectedBasedOnLateny); end @@ -144,7 +171,7 @@ rejectedBasedOnLateny = []; for eventNumber = 1:size(timeWarp, 1) rejectedBasedOnLateny = [rejectedBasedOnLateny find(abs(timeWarp(eventNumber, :)- mean(timeWarp(eventNumber, :))) > maxSTDForAbsolute* std(timeWarp(eventNumber, :)))]; - end; + end rejectedEpochesBasedOnLateny = unique_bc(rejectedBasedOnLateny); end @@ -158,9 +185,9 @@ if isempty(firstLatency) firstLatency = epoch.eventlatency{eventNumber}; - end; - end; - end; + end + end + end end function result = eventMeetsCondition(epoch, eventNumber, condition) @@ -173,10 +200,10 @@ for i=1:length(epochField) epochField{i} = strrep(epochField{i},'event',''); % remove event from the beginning of field names condition = strrep(condition, epochField{i}, ['cell2mat(epoch.event' epochField{i} '(' num2str(eventNumber) '))' ]); - end; + end result = eval(condition); - end; + end end @@ -185,15 +212,15 @@ if ischar(types) if iscell(eventStr) && isnumeric(cell2mat(eventStr)) eventStr = num2str(cell2mat(eventStr)); - end; + end result = strcmp(eventStr, types); else % it must be a cell of strs result = false; for i=1:length(types) result = result || strcmp(eventStr, types{i}); - end; - end; + end + end end end diff --git a/functions/miscfunc/makeelec.m b/functions/miscfunc/makeelec.m index 255dce810..5e05c2cc5 100644 --- a/functions/miscfunc/makeelec.m +++ b/functions/miscfunc/makeelec.m @@ -1,4 +1,4 @@ -% makeelec() - subroutine to make electrode file in eegplot() +% MAKEELEC - subroutine to make electrode file in EEGPLOT % % Usage: >> makeelec(chans) % >> [channames] = makeelec(chans) @@ -8,23 +8,34 @@ % % Author: Colin Humprhies, CNL / Salk Institute, 1996 % -% See also: eegplot() +% See also: EEGPLOT % Copyright (C) Colin Humphries, CNL / Salk Institute, Aug, 1996 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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. % 01-25-02 reformated help & license, added links -ad diff --git a/functions/miscfunc/makehelpfiles.m b/functions/miscfunc/makehelpfiles.m index 3c8d70e1f..545075f82 100644 --- a/functions/miscfunc/makehelpfiles.m +++ b/functions/miscfunc/makehelpfiles.m @@ -1,4 +1,4 @@ -% makehelpfiles() - generate function help pages +% MAKEHELPFILES - generate function help pages % % Usage: % >> makehelpfiles(list); @@ -22,39 +22,50 @@ % Copyright (C) Arnaud Delorme, CNL / Salk Institute, 2002 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 makehelpfiles( varargin ); if nargin < 1 help makehelpfiles; return; -end; +end opt = finputcheck( varargin, { 'folder' 'string' { } ''; 'outputfile' 'string' { } ''; 'title' 'string' { } '' }, 'makehelpfiles'); -if isstr(opt), error(opt); end; -if isempty(opt.folder), error('You need to specify a folder'); end; -if isempty(opt.outputfile), error('You need to specify an output file'); end; +if ischar(opt), error(opt); end +if isempty(opt.folder), error('You need to specify a folder'); end +if isempty(opt.outputfile), error('You need to specify an output file'); end fo = fopen( opt.outputfile, 'w'); if ~isempty(opt.title) fprintf(fo, '%%%s (%s folder):\n', opt.title, opt.folder); else fprintf(fo, '%% *Content of %s folder:*\n', opt.folder); -end; +end dirContent = dir(fullfile(opt.folder, '*.m')); dirContent = { dirContent.name }; for iFile = 1:length(dirContent) @@ -65,7 +76,7 @@ % get help from the first line if isempty(firstLine) || firstLine(1) ~= '%' firstLine = fgetl(fidTmp); - end; + end fclose(fidTmp); if isempty(firstLine) || firstLine(1) ~= '%' @@ -75,16 +86,16 @@ if ~isempty(indexMinus) firstLineText = deblank(firstLine(indexMinus(1)+1:end)); else firstLineText = deblank(firstLine(2:end)); - end; - if isempty(firstLineText), firstLineText = 'No help information'; end; - if firstLineText(1) == ' ', firstLineText(1) = []; end; - if firstLineText(1) == ' ', firstLineText(1) = []; end; - if firstLineText(1) == ' ', firstLineText(1) = []; end; + end + if isempty(firstLineText), firstLineText = 'No help information'; end + if firstLineText(1) == ' ', firstLineText(1) = []; end + if firstLineText(1) == ' ', firstLineText(1) = []; end + if firstLineText(1) == ' ', firstLineText(1) = []; end firstLineText(1) = upper(firstLineText(1)); - if firstLineText(end) ~= '.', firstLineText = [ firstLineText '...' ]; end; - end; + if firstLineText(end) ~= '.', firstLineText = [ firstLineText '...' ]; end + end refFunction = sprintf('%s', fileName(1:end-2), fileName(1:end-2)); fprintf(fo, '%% %-*s - %s\n', 50+length(fileName(1:end-2)), refFunction, firstLineText); -end; +end fclose( fo ); diff --git a/functions/miscfunc/makehtml.m b/functions/miscfunc/makehtml.m index 9fb08c5f0..3a5e6a067 100644 --- a/functions/miscfunc/makehtml.m +++ b/functions/miscfunc/makehtml.m @@ -1,4 +1,4 @@ -% makehtml() - generate .html function-index page and function help pages +% MAKEHTML - generate .html function-index page and function help pages % composed automatically from formatted Matlab function help messages % % Usage: @@ -28,8 +28,8 @@ % Optional inputs: % 'outputfile' - Output file name. {default: 'index.html'} % 'header' - Command to insert in the header of all .html files (e.g., javascript -% declaration or meta-tag). {default: javascript 'openhelp()' -% function. See help2htm() code for details.} +% declaration or meta-tag). {default: javascript 'OPENHELP' +% function. See HELP2HTM code for details.} % 'footer' - Command to insert at the end of all .html files (e.g., back % button. {default: reference back to the function-index file} % 'refcall' - Syntax format to call references. {default is @@ -41,7 +41,7 @@ % standard .html page link instead.} % 'fontindex' - Font for the .html index file (default: 'Helvetica') % 'backindex' - Background tag for the index file (c.f. 'background') -% 'mainheader' - Text file to insert at the beggining of the index page. Default is +% 'mainheader' - Text file to insert at the beginning of the index page. Default is % none. % 'mainonly' - ['on'|'off'] 'on' -> Generate the index page only. % {default: 'off' -> generate both the index and help pages} @@ -54,30 +54,41 @@ % { { 'toolbox', 'toolbox2' } 'Signal processing functions' 'adminfunc/eeg_helpsigproc.m' }}, ... % '/home/www/eeglab/allfunctions', 'mainheader', '/data/common/matlab/indexfunchdr.txt'); % -% See also: help2html2() +% See also: HELP2HTML2 % Copyright (C) Arnaud Delorme, CNL / Salk Institute, 2002 % -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. % -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: % -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +% 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 makehtml( directorylist, outputdir, varargin ); if nargin < 2 help makehtml; return; -end; +end if outputdir(end) ~= '/', outputdir(end+1) = '/'; end; @@ -85,44 +96,44 @@ g = struct( varargin{:} ); else g = []; -end; +end -try, g.mainonly; catch, g.mainonly = 'off'; end; -try, g.mainheader; catch, g.mainheader = ''; end; -try, g.outputfile; catch, g.outputfile = 'index.html'; end; -try, g.fontindex; catch, g.fontindex = 'Helvetica'; end; -try, g.backindex; catch, g.backindex = ''; end; -try, g.header; catch, g.header = [ '' ]; end; -try, g.background; catch, g.background = ''; end; -%try, g.background; catch, g.background = ''; end; -try, g.refcall; catch, g.refcall = 'javascript:openhelp(''%s.html'')'; end; -try, g.font; catch, g.font = 'Helvetica'; end; -try, g.footer; catch, g.footer = 'Back to functions'; end; -try, g.outputlink; catch, g.outputlink = [ '%s%s' ]; end; +try, g.mainonly; catch, g.mainonly = 'off'; end +try, g.mainheader; catch, g.mainheader = ''; end +try, g.outputfile; catch, g.outputfile = 'index.html'; end +try, g.fontindex; catch, g.fontindex = 'Helvetica'; end +try, g.backindex; catch, g.backindex = ''; end +try, g.header; catch, g.header = [ '' ]; end +try, g.background; catch, g.background = ''; end +%try, g.background; catch, g.background = ''; end +try, g.refcall; catch, g.refcall = 'javascript:openhelp(''%s.html'')'; end +try, g.font; catch, g.font = 'Helvetica'; end +try, g.footer; catch, g.footer = 'Back to functions'; end +try, g.outputlink; catch, g.outputlink = [ '%s%s' ]; end % read header text file % --------------------- if ~isempty(g.mainheader) doc = []; fid = fopen(g.mainheader , 'r'); - if (fid == -1), error(['Can not open file ''' g.mainheader '''' ]); end; + if (fid == -1), error(['Can not open file ''' g.mainheader '''' ]); end str = fgets( fid ); while ~feof(fid) str = deblank(str(1:end-1)); doc = [ doc str(1:end) ]; str = fgets( fid ); - end; + end g.backindex = [ g.backindex doc ]; -end; +end options = { 'footer', g.footer, 'background', g.background, ... 'refcall', g.refcall, 'font', g.font, 'header', g.header, 'outputlink', g.outputlink}; if strcmpi( g.mainonly, 'on') options = { options{:}, 'outputonly', g.mainonly }; -end; +end % ------------------------------------------- -% scrips which generate a web page for eeglab +% scripts which generate a web page for eeglab % ------------------------------------------- STYLEHEADER = '

%s

\n'; OPENWIN = [ '