We have developed a numerical method for calculating the second-harmonic generation (SHG) generated by an anisotropic material whose optical properties present an arbitrary modulation in one dimension. The method is based on the Berreman 4 × 4 matrix formalism, which is generalized to include nonlinear optical phenomena. It can be used under oblique incidences of the input beam, and is valid even when the SHG frequency is close to photonic bands, where the usual slowly-varying-amplitude approximation breaks down. As an example of application, we have studied the SHG performance of ferroelectric and helielectric fluids. The obtained results indicate that the present procedure may contribute to improving the structural design and enlarging the variety of nonlinear optical materials for application in optical devices.