Efficient and flexible Matlab implementation of 2D and 3D elastoplastic problems. Fully vectorized MATLAB implementation of various elastoplastic problems formulated in terms of displacement is considered. It is based on implicit time discretization, the finite element method and the semismooth Newton method. Each Newton iteration represents a linear system of equations with a tangent stiffness matrix. We propose a decomposition of this matrix consisting of three large sparse matrices representing the elastic stiffness operator, the strain-displacement operator, and the derivative of the stress-strain operator. The first two matrices are fixed and assembled once and only the third matrix needs to be updated in each iteration. Assembly times of the tangent stiffness matrices are linearly proportional to the number of plastic integration points in practical computations and never exceed the assembly time of the elastic stiffness matrix. MATLAB codes are available for download and provide complete finite element implementations in both 2D and 3D assuming von Mises and Drucker-Prager yield criteria. One can also choose several finite elements and numerical quadrature rules.