Back to the main page.

Bug 6 - add cfg.inputfile and cfg.outputfile to all fieldtrip functions

Status CLOSED FIXED
Reported 2010-01-07 11:54:00 +0100
Modified 2010-07-01 14:08:08 +0200
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P5 enhancement
Assigned to: Tim Engelkes
URL:
Tags:
Depends on:
Blocks:
See also:

Robert Oostenveld - 2010-01-07 11:54:39 +0100

Most functions work like this argout = funname(cfg, argin) it would be nice to be able to specify cfg.inputfile and cfg.outputfile instead of argin and argout, so that one could do funname(cfg) which would also read and write to disk


Robert Oostenveld - 2010-04-29 16:53:34 +0200

has been done for preprocessing


Robert Oostenveld - 2010-04-29 17:01:05 +0200

The following functions in fieldtrip/*.m use the nargin command and probably have variable number of input arguments roboos@mentat001> grep -l nargin *.m ft_appenddata.m ft_artifact_clip.m ft_artifact_ecg.m ft_artifact_eog.m ft_artifact_jump.m ft_artifact_muscle.m ft_artifact_threshold.m ft_artifact_zvalue.m ft_channelcombination.m ft_connectivityanalysis.m ft_databrowser.m ft_freqanalysis.m ft_headmodelplot.m ft_layoutplot.m ft_multiplotER.m ft_prepare_bemmodel.m ft_prepare_layout.m ft_prepare_leadfield.m ft_prepare_localspheres.m ft_prepare_mesh.m ft_prepare_singleshell.m ft_preprocessing.m ft_recodeevent.m ft_rejectartifact.m ft_rejectcomponent.m ft_singleplotER.m ft_sourceanalysis.m ft_sourcedescriptives.m ft_volumerealign.m sourcestatistics_randomization.m surfaceplot.m topoplot.m


Robert Oostenveld - 2010-04-29 17:02:25 +0200

(In reply to comment #2) you should also check on the presence of varargin


Robert Oostenveld - 2010-04-29 17:12:21 +0200

the following would make cfg.inputfile robust against the name of the variable in the file var = whos('-file', filename); if length(var)==1 % read the one variable in the file, regardless of how it is called tmp = load(filename); data = tmp.(var.name); clear tmp else % if multiple variables are present, then one of them MUST be called data load(filename, 'data'); end


Robert Oostenveld - 2010-04-29 17:22:51 +0200

(In reply to comment #4) more elaborate versions: function out = loadvar(filename, varname) var = whos('-file', filename); if length(var)==1 % read the one variable in the file, regardless of how it is called tmp = load(filename); data = tmp.(var.name); clear tmp else % if multiple variables are present, then one of them MUST be called data load(filename, 'data'); end function savevar(filename, varname, var) eval(sprintf('%s = var;', varname)); save(filename, varname);