The NetCDF library encountered an error during execution of 'create' function - 'Invalid argument (22)'

I am trying to create a netcdf file. Part of the code is this:

numcolO=numel(ObservationLong);
numrow=1;
numrow12=12;
numrow19=19;

NameNetcdf=char(strcat(MonthName(1),MonthName(2),MonthName(3),char(string(Year)),'.nc')); % Looks like 'JulAugSep2011.nc'

ncid = netcdf.create(NameNetcdf,'CLOBBER');% The line that doesn't work

dimidrow = netcdf.defDim(ncid,'rows',numrow);
dimidrowDates=netcdf.defDim(ncid,'timecol',numrow19);
dimidcol = netcdf.defDim(ncid,'length',numcolO);
dimidrowNames=netcdf.defDim(ncid,'namecol',numrow12);
%after this, the data gets read into the file

The error I get is

Error using netcdflib
The NetCDF library encountered an error during execution of 'create' function - 'Invalid argument (22)'.

Error in netcdf.create (line 61)
        ncid = netcdflib('create', filename, mode);

How do I solve this? I don't see which argument isn't correct.