How to write a 3d variable to a netcdf

3 views (last 30 days)
Amalu A
Amalu A on 23 Mar 2019
Commented: Amalu A on 30 Mar 2019
I want to extract a variable from an existing NetCDF file, Shift its dimensions and write the shifted variable to a new netcdf which is a copy of existing file by rewriting existing variable. So far I am able to extract a variable from an existing NetCDF file and Shift its dimensions but getting error when trying to write it to a new netcdf file
clc
clear all
data=ncread('MISR_AM1_AS_AEROSOL_P125_O075081_F13_0023.nc','/4.4_KM_PRODUCTS/Spectral_AOD_Scaling_Coeff')
Shift= shiftdim(data,1)
copyfile(which('MISR_AM1_AS_AEROSOL_P125_O075081_F13_0023.nc'),'myfile.nc');
ncdisp('myfile.nc','/4.4_KM_PRODUCTS/Spectral_AOD_Scaling_Coeff');
ncwrite('myfile.nc','/4.4_KM_PRODUCTS/Spectral_AOD_Scaling_Coeff',Shift);
ncdisp('myfile.nc','/4.4_KM_PRODUCTS/Spectral_AOD_Scaling_Coeff');
where
MISR_AM1_AS_AEROSOL_P125_O075081_F13_0023.nc
is the existing nc file
/4.4_KM_PRODUCTS/Spectral_AOD_Scaling_Coeff
Is the subfolder and existing variable
and the error which Iam getting is
Error using netcdflib
The NetCDF library encountered an error during execution of 'putVaraDouble' function - 'Start+count exceeds dimension
bound (NC_EEDGE)'.
Error in netcdf.putVar (line 84)
netcdflib(funcstr,ncid,varid,varargin{:});
Error in internal.matlab.imagesci.nc/write (line 831)
netcdf.putVar(gid, varid,start, count, varData);
Error in ncwrite (line 75)
ncObj.write(varName, varData, start, stride);
Error in netcdfread (line 9)
ncwrite('myfile.nc','/4.4_KM_PRODUCTS/Spectral_AOD_Scaling_Coeff',Shift);
Any suggetion or correction will be very much helpful,
Thanks alot in advance.
  7 Comments
Walter Roberson
Walter Roberson on 25 Mar 2019
Please experiment with the attached.

Sign in to comment.

Answers (0)

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!