How to shift the dimensions of a variable in a NetCDF file
3 views (last 30 days)
Show older comments
I have a NetCDF(example file) file which have different variables inside it. Have to choose a particular variable from the file(Spectral_AOD_Scaling_Coeff) which has three dimensions say 4032 x 496 x 3. Iwant to rewrite the variable by shifting the third dimension to first and first in position of third, for my example 3 x 496 x 4032 to 4032 x 496 x 3 and save the variable to same file. I have a number of such NetCDF file to do this same work so looking for a code which takes each file from a folder, do the stuff. any help is appreciated.
Thanks in advance
0 Comments
Accepted Answer
Walter Roberson
on 23 Mar 2019
I am not positive, but I think you might have to delete the variable out of the file before you can write in with the new ordering. But that is a bit of a problem, because netcdf does not have an explicit deletion interface.
It might be easier to copy all the variables to a new file, changing the one that is of interest to you.
The reorganization of the variable is easy at the MATLAB level:
permute(TheArray, [3 2 1])
But be careful, because netcdf are normally written in row-major order, whereas MATLAB works in column-major order. That is, in netcdf files, A(1,1) and A(1,2) are adjacent in the file, whereis in MATLAB, A(1,1) and A(2,1) are adjacent in memory. You should work out what order of elements you want to create in the file.
More Answers (0)
See Also
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!