Back to the main page.

Bug 3413 - MUSIC computation doesn't account for inside vs. outside elements of leadfield

Reported 2018-02-17 23:15:00 +0100
Modified 2018-03-02 15:03:51 +0100
Product: FieldTrip
Component: inverse
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P3 normal
Assigned to: Jan-Mathijs Schoffelen
Depends on:
See also:

Josh Diamond - 2018-02-17 23:15:18 +0100

MUSIC works well when I pass a leadfield for which all elements are inside the headmodel volume. However, I tried passing a leadfield for which only some elements are inside the headmodel. This was built with ft_prepare_leadfield, and it already contained a field leadfield.inside, a logical detailing which leadfield elements are inside the headmodel. The problem is that music.m does not limit the leadfield to only inside elements. It limits the dipole positions to only inside elements, but does not do the same for the leadfield. So the result is that, in music.m line 111, lf is equal to [], and so I get: Error using * Inner matrix dimensions must agree. Some example code is: load vol; % From tutorials pos = vol.bnd.pos; minMax = [min(pos)' max(pos)']; % Create linear spaces. x = minMax(1,1):6:minMax(1,2); y = minMax(2,1):6:minMax(2,2); z = minMax(3,1):6:minMax(3,2); % Create grid [x,y,z] = meshgrid(x,y,z); x = x(:); y = y(:); z = z(:); lattice = [x y z]; cfg = []; cfg.elec = elec; % From tutorial cfg.grid.pos = lattice; cfg.grid.unit = 'mm'; cfg.headmodel = vol; leadfield = ft_prepare_leadfield(cfg); load tlck; % From tutorials cfg = []; cfg.method = 'music'; cfg.grid = leadfield; cfg.headmodel = vol; = 1; source = ft_sourceanalysis(cfg,tlck); I was able to achieve a fix with the following solutions. In music.m: line 75: add origleadfield = dip.leadfield; Line 79: add dip.leadfield = dip.leadfield(originside); Line 127: add dipout.leadfield = origleadfield; Thank you and let me know if you have any questions. Josh

Jan-Mathijs Schoffelen - 2018-02-27 16:28:14 +0100

Thanks for reporting this Josh, Usually I'd refer you to github to implement the fix in your own copy of fieldtrip, and to issue a PR (pull request). Yet, I have changed the code based on your suggestion myself (adding a check for the presence of the leadfield, which is not necessarily always there I think). Thanks again, if you pull a fresh copy of the repository, I think it should work.

Jan-Mathijs Schoffelen - 2018-03-02 15:03:51 +0100