Skip to main content

electrodes coordinates for Matlab

If one wants to read elec.dat in Matlab and graph electrodes in 3D space,
or use Matlab to add new electrodes in elec.dat one need to be aware of a few things:

- elec.dat has the following fields:
column 1: electrode number, columns 2, 3: theta, phi in degrees, column 4: electrode name
(see http://elan.lyon.inserm.fr/?q=elec_definition)

The theta and phi coordinates are different in Matlab {for use in [x,y,z] = sph2cart(THETA,PHI,R) for instance} and Elan, such that:

PHI in Matlab is labelled theta in Elan= latitude,
and THETA in Matlab is phi in Elan = longitude,

In addition, Matlab latitude is taken from 0 on the XY plane, such that:

latitude_matlab = 90 - latitude_Elan (in degree)

in summary:

theta_matlab = phi_elan
phi_matlab = 90 - theta_elan

Finally, angles must be in radians in Matlab.

here is a short code to graph electrodes on a unit sphere in Matlab (provided you have theta, phi, and names of elec.dat in 3 vectors: theta, phi, nam)

% POST
%Transform Elan Theta/Phi coordinates into cartesian coordinate to plot in
%3D
% WARNING: Phi and Theta labelling are reversed from Elan to Matlab
% + the vertical angle (Elan=theta, Phi=Matlab) is opposite i.e.
% phi_matlab = 90 - theta_elan
% Angles must be in rad in Matlab
% Things are clearly spelled out below (and thus can be compressed) for
% clarity

clear;
load('elec.mat');

elec=[1:64]; % channels to plot

theta_elan=theta(elec);
phi_elan=phi(elec);
rho=1;

% Elan to Matlab coordinates
theta_mat=phi_elan;
phi_mat=90-theta_elan;

% Degrees into radians
theta_rad = pi * (theta_mat) / 180;
phi_rad = pi * (phi_mat) / 180;
% Spheric to cartesian
[x,y,z]=sph2cart(theta_rad,phi_rad,rho);
%plot
plot3(x,y,z,':ko','MarkerFaceColor','y','MarkerEdgeColor','k');
text(x,y,z,nam(elec)); line([-1.2 1.2],[0 0],[0 0],'color','b');%x axis
line([0 0],[-1.2 1.2],[0 0],'color','r');%y axis
line([0 0],[0 0],[-1.2 1.2],'color','g');%z axis

%draw sphere
tt=linspace(0,2*pi);
pp=linspace(-pi/2,pi/2);
[tt,pp]=meshgrid(tt,pp);
rr=.95;
[xx,yy,zz]=sph2cart(tt,pp,rr);
hold on;
mesh(xx,yy,zz);colormap('gray')