File Exchange

image thumbnail

nccreatewrite(varar​gin)

version 1.0.0.0 (3.33 KB) by ANKUR KUMAR
Create a .nc file

2 Downloads

Updated 24 May 2019

View License

Function:
One can create a netcdf4 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('test1.nc','lat',{'lat','c'},lat)

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 {'a','b'}
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.

Example:
clc
clear
lon=(65:0.5:95)';
lat=(3:0.5:35)';
data=randi(20,65,61,365);
delete test1.nc
nccreatewrite('test1.nc','lat',{'lat','c'},lat)
nccreatewrite('test1.nc','lon',{'lon','c'},lon)
nccreatewrite('test1.nc','TC',{'lat','lon','days'},data)

Please send your suggestions to the email id: ankurk017@gmail.com or
416AS2025@nitrkl.ac.in

Cite As

ANKUR KUMAR (2019). nccreatewrite(varargin) (https://www.mathworks.com/matlabcentral/fileexchange/65636-nccreatewrite-varargin), MATLAB Central File Exchange. Retrieved .

ankurk017_nccreatewrite

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags