This paper presents an efficient and compact MATLAB code for 3D topology optimization of multi-materials. The multi-material problem using a mapping-based material interpolation function is adopted from previous work, in which each material is modeled in the same way, presenting a clear (clean) result of 0 and 1 for each material of the optimized structures, without gray elements, thus facilitating the manufacturing process. A new projection function, the sigmoid function, is adopted for the filtered design variables for each material in the domain. The proposed method improves computational efficiency, reducing computational costs by up to 36.7%, while achieving a 19.1% improvement in the objective function compared to the hyperbolic tangent function. A multi-material topology optimization solution with minimal compliance under volume constraints, including details of the optimization model, filtering, projection, and sensitivity analysis procedures, is presented. Numerical examples are also used to demonstrate the effectiveness of the code, and the influence of the position of the support on the optimized results is also proven. The complete MATLAB code for 3D elastic structures is presented as an example.