Writing time series data to a netCDF file from workspace

9 visualizaciones (últimos 30 días)
Deepa Maheshvare
Deepa Maheshvare el 17 de Jul. de 2020
Editada: Deepa Maheshvare el 17 de Jul. de 2020
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 comentario
Deepa Maheshvare
Deepa Maheshvare el 17 de Jul. de 2020
Editada: Deepa Maheshvare el 17 de Jul. de 2020
Suggestions on how to create different variables in a single file, if possible, will be useful.

Iniciar sesión para comentar.

Respuestas (1)

Bhupendra Prajapati
Bhupendra Prajapati el 17 de Jul. de 2020
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 comentarios
Deepa Maheshvare
Deepa Maheshvare el 17 de Jul. de 2020
Thanks . But isn't possible to create a second variable instead of creating 2 separate files?
Deepa Maheshvare
Deepa Maheshvare el 17 de Jul. de 2020
I would also like to know how to define attributes to a variable. For instance, I have to define the units of variable `time`.

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by