nccreatewrite
Versione 2.0.0.1 (283 KB) da
ANKUR KUMAR
Creates the NetCDF file directly, and these NetCDF files are readbale in GrADS. Get rid of writing the long commands everytime to create
Function:
One can create a NetCDF file with the predefined MATLAB
function using nccreate and ncwrite. This function is a
combination of these two predefined functions. One can use this
to save the time and get rid of writing the same commands for
storing multi variables in a nc file.
Syntax:
nccreatewrite('sample_file.nc','variable',{'lon','lat','lev'},randi(20,20,30,5))
Inputs:
First input should be the name of the nc file in which you want
to store the data.
Second input should be the name of the variable in which you
want to store the specific variable.
Third argument should be in braces (not structure) which must
contains the number of variables as that of the size of the
data you want to store.
ex: If you want to store 'lat' whose dimensions is 5*1, then
third argument should be {'lat'}
The above is becasue of MATLAB also stores the variable
dimensions seprately, not in the variable list.
You can see this when you use ncdisp to see the listed
variables in nc file.
Fourth argument should be the data you want to write in nc
file.
Fifth argument is an optional argument, and if provided, it should
be the attributes of the variable.
Example:
random_data = normrnd(3,10,[20,30,5])+273;
filename='sample.nc';
delete(filename)
lon_att.standard_name='longitude';
lon_att.long_name='longitude';
lon_att.units='degrees_east';
lon_att.axis='X';
nccreatewrite(filename,'lon',{'lon'},[65:84],lon_att)
lat_att.standard_name='latitude';
lat_att.long_name='latitude';
lat_att.units='degrees_north';
lat_att.axis='Y';
nccreatewrite(filename,'lat',{'lat'},[1:30],lat_att)
lev_att.long_name='generic';
lev_att.units='level';
lev_att.axis='Z';
nccreatewrite(filename,'lev',{'lev'},[1:5],lev_att)
nccreatewrite(filename,'TC',{'lon','lat','lev'},random_data)
ncdisp(filename)
Please send your suggestions to the email id: ankurk017@gmail.com or
ankur.kumar@nsstc.uah.edu
Cita come
ANKUR KUMAR (2024). nccreatewrite (https://www.mathworks.com/matlabcentral/fileexchange/65636-nccreatewrite), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Creato con
R2021a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Scopri di più su MATLAB Compiler SDK in Help Center e MATLAB Answers
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.