Back to the main page.
Bug 2711 - ft_math checks wether a field is present, then crashes anyways if it is not
Status | CLOSED FIXED |
Reported | 2014-09-29 12:09:00 +0200 |
Modified | 2015-02-11 10:40:46 +0100 |
Product: | FieldTrip |
Component: | core |
Version: | unspecified |
Hardware: | PC |
Operating System: | Linux |
Importance: | P5 major |
Assigned to: | Robert Oostenveld |
URL: | |
Tags: | |
Depends on: | |
Blocks: | |
See also: |
Maarten - 2014-09-29 12:09:03 +0200
It is about this loop in ft_math (causing errors in line 361). keepfield = {'grad', 'elec'}; for j=1:numel(keepfield) if isfield(varargin{i}, keepfield{j}) keep = true; tmp = varargin{i}.(keepfield{j}); else keep = false; end for i=1:numel(varargin) if ~isequal(varargin{i}.(keepfield{j}), tmp) keep = false; break end end if keep data.(keepfield{j}) = tmp; end end For me, it crashes because I have no fields called 'elec'. After checking whether there is a field called varargin{i}.elec (returning 0), it goes on to the statement "if ~isequal(varargin{i}.(keepfield{j}), tmp)" which crashes because of a reference to non-existent field 'elec'. I think breaking from the loop at the isfield bit would work, right? Best, Maarten
Maarten - 2014-09-29 12:18:53 +0200
edit: Coming to think of it, that probably wouldn't work, but you get the idea.
Maarten - 2014-09-29 13:26:35 +0200
keepfield = {'grad', 'elec'}; for j=1:numel(keepfield) if isfield(varargin{i}, keepfield{j}) keep = true; tmp = varargin{i}.(keepfield{j}); else keep = false; end if keep for i=1:numel(varargin) if ~isequal(varargin{i}.(keepfield{j}), tmp) keep = false; break end end end if keep data.(keepfield{j}) = tmp; end end something like this.
Robert Oostenveld - 2014-09-29 13:31:39 +0200
thanks for reporting. the bug is due to the first isfield(varargin{i}, keepfield{j}) which should be isfield(varargin{1}, keepfield{j}) On the second keepfield it would otherwise start with the incorrect "i", but should start with "1". Furthermore it did not check the absence of the field correctly I fixed it. mac011> svn commit ft_math.m Sending ft_math.m Transmitting file data . Committed revision 9866.