We study frictionless matching in large economies with and without market imperfections, providing sufficient conditions for monotone matching that are weaker than those previously known. Necessary conditions, which depend on a key analytical object we call the surplus function, are also offered. Changes in the surplus yield valuable information about the comparative statics of matching patterns across environments. We apply our framework to some examples adapted from the literature, accounting for and extending several comparative-static and welfare results. We also explore the dependence of the matching pattern on the type distribution.