I have a list of strings that I want to save into a netCDF using MATLAB. However, I'm having trouble creating the file.
method_ID is a char array like this:
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
'55-059-0019-88101-1'
I tried to do the following, but it saves the strings out as one long string instead of 10 strings.
filename = ['PM25_24hr_',num2str(years(y)),'_EPA_AQS.nc'];
ncfilename = ['/data3/jg3223/PM25/netCDF/',filename];
method_ID = char(data_PM25{:,1});
% Create the file, overwriting if already exists (Clobber) and
% 64-bit offset (Allow easier creation of files and variables which are larger
% than two gigabytes.)
mode = bitor(netcdf.getConstant('CLOBBER'),netcdf.getConstant('64BIT_OFFSET'));
ncid = netcdf.create(ncfilename,mode);
% Define (file) global attributes
globalVarId=netcdf.getConstant('GLOBAL');
netcdf.putAtt(ncid,globalVarId,'name','PM25_24hr_AQS');
[a,b] = size(method_ID);
IDDimId = netcdf.defDim(ncid,'method_ID',a*b); % I know this size is wrong, but using `length(method_ID)` runs a size error later on
% Define variables, starting with coordinate variables,
% with appropriate names, types, and dimensions
IDVarId = netcdf.defVar(ncid,'method_ID','char',IDDimId);
% Exit the "define mode", i.e., structure creation mode
netcdf.endDef(ncid);
method ID
netcdf.putVar(ncid,IDVarId,method_ID);
% Close the netCDF file
netcdf.close(ncid);