Matlab scripting examples

We will list useful scripts / command-line calls that are shipped within Lead-DBS on this site. Please note that a lot of these scripts are buggy and may not be well maintained. Also, the documentation may be outdated. But they provide some insight about useful tools for expert users.

3D Visualization / Elvis viewer


ea_mnifigure('DISTAL Minimal (Ewert 2017)');

This snippet will open the 3D viewer "Elvis" of Lead-DBS with an atlas. It is a normal MATLAB figure, so you can then plot additional content onto it.


ea_keepatlaslabels('on'); ea_keepatlaslabels('off');

This call will hide all atlas structures from an open viewer that are not specified in the script.


ea_setplanes(0,-30,nan); % will not show the z-plane at all

This call will move or hide (when supplying NaN) the MRI planes to specific mm values.


v = ea_view();

Store the current 3D view (v = ea_view;) as variable v or set the current 3D view to the view stored in v.

Elvis scripting example scripts

ea_mnifigure('DISTAL Minimal (Ewert 2017)'); % open up Elvis viewer
ea_keepatlaslabels('GPI'); % hide all structures except GPi
load([ea_space([],'atlases'),'DISTAL Minimal (Ewert 2017)',filesep,'atlas_index.mat']); % manually load definition of DISTAL atlas.
rSTN=atlases.roi{1,1}.fv; % extract the right STN.
rSTN=reducepatch(rSTN,0.5); % reduce patch a bit.
patch('Faces',rSTN.faces,'Vertices',rSTN.vertices,'facecolor','none','edgecolor','w'); % visualize the right STN as wireframes.
lSTN=atlases.roi{1,2}.fv; % do the same for the left STN.
ea_setplanes(0,-30,nan); % set planes to a nice view.

% now define a specific camera view: 126.0430;
v.el= -34.9893;
v.camva= 0.4648;
v.camup= [0 0 1];
v.camproj= 'orthographic';
v.camtarget= [-1.2419 -23.0911 3.9242];
v.campos= [1.0973e+03 1.0671e+03 -1.0542e+03];
ea_view(v); % apply view.

Export / Data Visualization



Overlay a nifti file to the MNI space surfice templates and export results as png.

Coordinates and image manipulation

Querying electrode placement

Electrode coordinates are stored inside the ea_reconstruction.mat files inside patient folders and also in the M.elstruct variable of the Lead_groupanalysis.matfiles of Lead group projects.


will deliver the right-hemispheric ({1}) x (laterality), y (anterio-posterior axis) and z (dorso-ventral / superior-inferior axis) coordinates in template space. Usually (by default) these will be within ICBM 152 2009b Nonlinear Asymmetric space, the most modern and precise "MNI space". See here for more about different spaces. Left hemispheric electrodes will be stored in the second cell ({2}). To get coordinates in native subject space, use the reco.native.coords_mm (before brain shift correction, i.e. inside the postoperative volume) or the reco.scrf.coords_mmentry (after brain shift correction, i.e. inside the anchor modality. Note that those are not ACPC coordinates.

By default, ACPC coordinates are not computed, but this can be done. To enable it, change the line prefs.reco.saveACPC=0;to prefs.reco.saveACPC=1; within the preferences file (to open the preferences file hit cmd+P in the Lead-DBS main GUI.

Once this flag is enabled, the recovariable will have another entry called acpcwith the same logic.

If you are dealing with more than two electrodes, the cells will have more than two entries but usually, right hemispheric electrodes should be stored in the first and left in the second entry.

Inside these entries, contacts are numbered from bottom to top, for instance


will deliver the left hemispheric ({2}) third most ventral ((3,:)) contact inside the native space anchor modality (which is usually the T1 image). Of note, those are usually not that useful and not comparable across subjects. The mni or acpc coordinates are and we strongly suggest using mnicoordinates for comparisons or statistical analyses.


This function will make a spherical region of interest around a user identified mni coordinates. It takes file name, mni coordinates in (mm), radius (in mm), and path of space template file in which the sphere will be identified, as arguments



Converts voxel-coordinates to mm-coordinates. Coordinates need to be row vector: N*3

ea_vox2mm(vox, transform);

ans =

  -37.5000  -24.5000   -6.0000


Flip files / coords nonlinearly from Left to Right hemisphere (or vice versa) based on asymmetric template


Last updated