Back to the main page.

Bug 3163 - error in pos2dim - can't index with NaNs

Status CLOSED FIXED
Reported 2016-07-15 18:34:00 +0200
Modified 2016-11-29 09:00:58 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P5 normal
Assigned to: Jan-Mathijs Schoffelen
URL:
Tags:
Depends on:
Blocks:
See also:

Robin - 2016-07-15 18:34:01 +0200

When trying to use ft_sourcewrite I had an error in pos2dim. The "dim" variable is initialized as NaNs and then used to index - this causes an error (indexes must be positive integers or logical). I fixed it with the following: robini@robini2-pc ~/e/fieldtrip> git di private/pos2dim.m diff --git a/private/pos2dim.m b/private/pos2dim.m index 1e0c65f..6c96f6f 100644 --- a/private/pos2dim.m +++ b/private/pos2dim.m @@ -28,7 +28,7 @@ dim = nan(1,3); [tmp, ind] = max(dpos,[],2); dim(1) = find(tmp>1.5,1,'first'); dpos = dpos(dim:dim:npos-1,:); -[tmp, ind] = max(dpos(:,setdiff(1:3, ind(dim))),[],2); +[tmp, ind] = max(dpos(:,setdiff(1:3, ind(dim(1)))),[],2); dim(2) = find(tmp>1.1*min(tmp),1,'first'); % this threshold seems to work o -dim(3) = npos./prod(dim); +dim(3) = npos./prod(dim(1:2));


Jan-Mathijs Schoffelen - 2016-07-18 13:54:23 +0200

Thanks Robin, Would it be a big deal for to make a pull request out of this? JM


Robin - 2016-07-18 14:08:23 +0200

Done - hope its correct! https://github.com/fieldtrip/fieldtrip/pull/196 I didn't really understand fully the computation here - I just fixed the error.


Jan-Mathijs Schoffelen - 2016-07-18 15:33:49 +0200

Thanks, (I don't understand the computations either anymore, but it seems to work, apart from the occasional glitch).


Jan-Mathijs Schoffelen - 2016-07-18 15:34:58 +0200

merged Robin's pull request. Thanks again.