Writing time series data to a netCDF file from workspace

8 次查看(过去 30 天)
I have a worspace variable containing time varying data of a parameter `p` obtained at different coordinate positions. The rows correspond to different coordinate positions of a grid and columns correspond to diferent time points. I would like to save this data in mat file to netCDF format. I've tried the following to write the workspace variable `time` following the examples provided here
header = ['x', 'y', 'z', '0.2s', '0.4s', '0.6s', '0.8s', '1.0s']
time = [0.2 0.4 0.6 0.8 1.0];
mydata = rand(10,8) %first 3 columns (x,y,z) coordinates next 5 time series data at 0.2,0.4,0.6,0.8,1 seconds
% define mode
ncid = netcdf.create('myfile.nc','CLOBBER');
dimid = netcdf.defDim(ncid,'my_dim',length(time))
varid = netcdf.defVar(ncid,'time','NC_BYTE',dimid)
netcdf.endDef(ncid)
% data mode
netcdf.putVar(ncid,varid,time)
netcdf.close(ncid)
% verify
ncid2 = netcdf.open('myfile.nc','NC_NOWRITE');
x = netcdf.getVar(ncid2,0);
whos x
netcdf.close(ncid2)
I'd like to ask for suggestions on how to write the rest of the data ( coordinates and time-varying data of `p` stored in `mydata`) in the same netcdf file.
  1 个评论
Deepa Maheshvare
Deepa Maheshvare 2020-7-17
编辑:Deepa Maheshvare 2020-7-17
Suggestions on how to create different variables in a single file, if possible, will be useful.

请先登录,再进行评论。

回答(1 个)

Bhupendra Prajapati
You could create another netcdf file put write your data in that file and then merge it with your myfile.nc
Refer to the link below for instructions on merging.
https://www.mathworks.com/help/matlab/import_export/exporting-to-network-common-data-form-netcdf-files.html?s_tid=answers_rc2-3_p6_MLT#bsxb8lu-1
  2 个评论
Deepa Maheshvare
Deepa Maheshvare 2020-7-17
Thanks . But isn't possible to create a second variable instead of creating 2 separate files?
Deepa Maheshvare
Deepa Maheshvare 2020-7-17
I would also like to know how to define attributes to a variable. For instance, I have to define the units of variable `time`.

请先登录,再进行评论。

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by