decomposes a 3D matrix