The BEM has great applications for numerically solving engineering problems, especially for irregular space domains. It is one of the discretization methods. For the application of BEM for the mentioned problem, see below
Article Lead field computation for the electrocardiographic inverse ...
I have worked with Fieldtrip and seen this paper, but I want to write my own MATLAB code and I want to learn it in detail. I mean I know the structure of extracting BEM leadfield but I don't know how I can write its MATLAB code.