Matlab : Export netcdf timestamped variable

99 views Asked by At

I'm saving a 1x50 array in a variable in a netCDF file and this operation is done every ~10sec. I would like also to save matlab'time datestr(now) (YYYY-MM-DDTHH:MM:SS).

How should I do ? I tried to store the date (datestr(now)) in a time variable without success.

Kind regards,

2

There are 2 answers

0
CUEIRB22 On

I finaly succeed in store time in my netCDF file. 1. I defined a 'time' dimension 2. I defined a dimension for my 1x50 value then I wrote my data

ncwrite(ncfilename, 'data',myData.',[1 i]);
ncwrite(ncfilename, 'time',myData_triggertime,i);

where myData (my 1x50 array), myData_triggertime (=datestr(now)) are updated at each acquisition loop and i incremented at each loop.

kind regards

1
Pieter12345 On

To store a variable in your workspace to a .mat file, you can use this:

variable = 1; % Variable to store.
fileName = ['fileName - ', datestr(now, 'yyyy-mm-dd HH.MM.SS'), '.mat'];
save(fileName, '-mat', 'variable');

Note that a ':' in the date string will make the save() function throw an error.