function [XB,YB,Bx,By] = postprocB(x,e,B,m,n)

% [XB,YB,Bx,By] = postprocB(x,e,B,m,n)
%            It creates coordinate matrices XB and YB
%            consisting of element mass points,
%            and the matrices Bx, By consisting
%            of elementwise constant vectors
%            of magnetic induction.
%            It is intended for quiver plot-function.

XB = zeros(m,n);
YB = zeros(m,n);
Bx = zeros(m,n);
By = zeros(m,n);

ne = max(size(B));

for i=1:ne
    ei = e(i,:);
    
    x1 = x(:,ei(1));
    x2 = x(:,ei(2));
    x3 = x(:,ei(3));

    Ri = [x2-x1 x3-x1];
    ri = x1;
    
    massPointi = Ri*[1/3;1/3] + ri;
    
    index1 = floor(i/(2*n)) + n*rem(i,2*n) + 1;
    index2 = rem(i,2*n) + 1;
    
    XB(index1,index2) = massPointi(1);
    YB(index1,index2) = massPointi(2);

    Bx(index1,index2) = B(1,i);
    By(index1,index2) = B(2,i);
   
end
