How to create a grid and mask selected areas

Dear all, I have a data (xyz) which contain some grid cells without information (NaN). I will like to convert it to a grid, such that the NaN cells are masked. How can this be done? Thank you

xyz2grd converts from gridded xyz ascii data into grid binary formats.

such that the NaN cells are masked.

This, however, I don’t understand. Grid cells are never masked. Either they have valid numbers or not (NaNs)

Thanks you. I am quite familiar with gridding. I use blockmean and surface.
gmt blockmean $infile -V -R$lon_min/$lon_max/$lat_min/$lat_max -I2m | gmt surface -Goutgrid.grd -R$lon_min/$lon_max/$lat_min/$lat_max -I2m -V

But in this particular case, I want cells with NaN covered with uniform color e.g. -G200.

That’s exactly the point. grids have no color. They are grids not images.
Ofc you can make images out of grids and if you want to assign a particular color to NaNs set COLOR_NAN to the value you want. See doc of makecpt -M

BTW, the grid computed with surface like that will have no NaNs because all nodes are interpolated.

Thank you. I realize this, so as an alternative approach I decided to play around with GRDMATH produce the result. It worked.

@JoshMarine or any one else, please can you tell how you use grdmath or any gmt function to get the NAN data masked. I have similar problem. I have xyz data and I want the NaN (s) masked , such that when I produce a map it appears as gray color similar to this figure

Please see the response here: How to create grid and mask NaN areas with gray color.