1 function p=hexa_sub(X,K,i)
3 % extract one submatrix from global matrix from i to i+1
5 % X mesh coordinates, cell vector 3
7 % i index of lower left front corner
9 % p.S2 2D submatrix of K
10 % p.X 3 by 8 matrix of coordinates, same as in hexa
11 % p.S6 submatrix of K as 6D
17 p.S6=zeros(2,2,2,2,2,2);
23 ix=sub2ind(n,i(1)+i1,i(2)+i2,i(3)+i3); % global index
24 ik=sub2ind([2,2,2],1+i1,1+i2,1+i3); % local index
25 p.X(1,ik)=X{1}(i(1)+i1,i(2)+i2,i(3)+i3);
26 p.X(2,ik)=X{2}(i(1)+i1,i(2)+i2,i(3)+i3);
27 p.X(3,ik)=X{3}(i(1)+i1,i(2)+i2,i(3)+i3);
31 jx=sub2ind(n,i(1)+j1,i(2)+j2,i(3)+j3);
32 jk=sub2ind([2,2,2],1+j1,1+j2,1+j3);
34 p.S6(i1+1,i2+1,i3+1,j1+1,j2+1,j3+1)=K(ix,jx);