mod(arg(solver.Ez),2*pi) can be used to find the output phase (in radians) of the grating between 0 and 2pi. "solver" in the expression, if you are working with wave optics module and frequency domain is "ewfd". Referring to: Mathematical Functions (comsol.com)