Writing time series data to a netCDF file from workspace

조회 수: 6 (최근 30일)
Deepa Maheshvare
Deepa Maheshvare 2020년 7월 17일
편집: Deepa Maheshvare 2020년 7월 17일
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
Bhupendra Prajapati 2020년 7월 17일
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`.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by