Abstract: We study numerically and analytically the dynamics of defect formation during a finite-time quench of the two-dimensional Swift-Hohenberg (SH) model of Rayleigh-Bénard convection. We find that the Kibble-Zurek picture of defect formation can be applied to describe the density of defects produced during the quench. Our study reveals the relevance of two factors: the effect of local variations of the striped patterns within defect-free domains and the presence of both pointlike and extended defects. Taking into account these two aspects we are able to identify the characteristic length scale selected during the quench and to relate it to the density of defects. We discuss possible consequences of our study for the analysis of the coarsening process of the SH model.