Move the preallocation to the outer loop otherwise the results from the previous iteration are obliterated on the next one
Add new (optional) variable to supply (the MATLAB mesh structure). This is used to get the sigma coordinate levels and layers to output to the NetCDF file. Also made some small stylistic changes (using repmat instead of ones and a mutiplication, for example)
Added two new outputs to the MATLAB mesh structure (the sigma layer and level values)